Laravel 如何管理社交网络主页
Laravel how to manage home of social networks
请问如何在登录程序后将主页处理成社交网络。感谢回复
您是通过 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 的完整社交网络,您可能会发现比您需要的更多的东西。
希望对你有帮助
请问如何在登录程序后将主页处理成社交网络。感谢回复
您是通过 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 的完整社交网络,您可能会发现比您需要的更多的东西。
希望对你有帮助