43 lines
1.0 KiB
PHP
43 lines
1.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Models\Post;
|
||
|
use App\Models\Status;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class IndexController extends Controller
|
||
|
{
|
||
|
public function index() {
|
||
|
|
||
|
if(auth()->user()) {
|
||
|
$posts = Post::wherehas("status", function ($query) {
|
||
|
$query->where("name", "!=", "Pending")
|
||
|
->orWhere("user_id", "=", auth()->id());
|
||
|
})->get();
|
||
|
|
||
|
return view('index')->with("posts", $posts);
|
||
|
}
|
||
|
|
||
|
$posts = Post::wherehas("status", function ($query) {
|
||
|
$query->where("name", "!=", "Pending");
|
||
|
})->get();
|
||
|
|
||
|
// $posts = Post::all();
|
||
|
|
||
|
return view('index')->with("posts", $posts);
|
||
|
}
|
||
|
|
||
|
public function adminIndex(Request $request) {
|
||
|
$posts = Post::all();
|
||
|
|
||
|
if($request->get("type") != null) {
|
||
|
$posts = Post::wherehas("status", function ($query) {
|
||
|
$query->where("name", "=", "Pending");
|
||
|
})->get();
|
||
|
}
|
||
|
|
||
|
return view('admin.posts')->with("posts", $posts);
|
||
|
}
|
||
|
}
|