我会问你如何在登录程序后将主页处理成社交网络。谢谢你的回复
答案 0 :(得分:1)
您是通过Composer初始化项目还是手动创建项目?
然而: 主页视图:
@extends('layouts.app')
@section('content')
<div class="h-20"></div>
<div class="container">
<div class="row">
<div class="col-md-3">
@include('widgets.sidebar')
</div>
<div class="col-xs-12 col-md-3 pull-right">
<div class="hidden-sm hidden-xs">
@include('widgets.suggested_people')
</div>
</div>
<div class="col-md-6">
@include('widgets.wall')
</div>
</div>
</div>
@endsection
@section('footer')
<script type="text/javascript">
WALL_ACTIVE = true;
fetchPost(0,0,0,10,-1,-1,'initialize');
</script>
@endsection
主页控制器:
<?php
namespace App\Http\Controllers;
use App\Library\IPAPI;
use App\Library\sHelper;
use App\Models\Group;
use App\Models\Hobby;
use App\Models\Post;
use App\Models\User;
use DB;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class HomeController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$user = Auth::user();
$wall = [
'new_post_group_id' => 0
];
return view('home', compact('user', 'wall'));
}
public function search(Request $request){
$s = $request->input('s');
if (empty($s)) return redirect('/');
$user = Auth::user();
$posts = Post::leftJoin('users', 'users.id', '=', 'posts.user_id')
->where(function($query) use ($user) {
$query->where('users.private', 0)->orWhere(function($query) use ($user){
$query->whereExists(function ($query) use($user){
$query->select(DB::raw(1))
->from('user_following')
->whereRaw('user_following.following_user_id = users.id and user_following.follower_user_id = '.$user->id);
});
})->orWhere(function($query) use ($user){
$query->where('users.private', 1)->where('users.id', $user->id);
});
})->where('posts.content', 'like', '%'.$s.'%')->where('posts.group_id', 0)
->groupBy('posts.id')->select('posts.*')->orderBy('posts.id', 'DESC')->get();
$comment_count = 2;
$users = User::where('name', 'like', '%'.$s.'%')->orWhere('username', 'like', '%'.$s.'%')->orderBy('name', 'ASC')->get();
return view('search', compact('users', 'posts', 'user', 'comment_count'));
}
}
消息来源:https://github.com/lvntayn/laravel-social-network
这是一个使用Laravel的完整社交网络,可能你会找到比你需要的更多的东西。
我希望它有所帮助