Bulletinboard/app/Http/Controllers/IndexController.php

43 lines
1.0 KiB
PHP
Raw Normal View History

2021-02-24 09:01:35 +00:00
<?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);
}
}