-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcommentcontroller.php
More file actions
61 lines (57 loc) · 1.89 KB
/
commentcontroller.php
File metadata and controls
61 lines (57 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace App\Http\Controllers;
use App\User;
use App\comment;
use App\blog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Auth;
class commentcontroller extends Controller
{
function add(Request $req){
$userid = Auth::user()->id; //userid
$data = new comment;
$data->comment = $req->comment;
$data->user_id = $userid;
$data->blog_id = $req->id;
$data->save();
return redirect('/homepage');
}
function select(){
if(Auth::user()->role == "admin")
{
$data = comment::all();
$commment = [];
for($i = 0; $i < sizeof($data); $i++){
array_push($commment,$data[$i]);
$name = User::find($data[$i]['user_id']);
$commment[$i]['name'] = $name->username;
}
return view('dashboard.dash_comments',["data"=>$commment]);
}
else{
$data = comment::all();
$commment = [];
for($i = 0; $i < sizeof($data); $i++){
array_push($commment,$data[$i]);
$name = User::find($data[$i]['user_id']);
$commment[$i]['name'] = $name->username;
}
$username = Auth::user()->name;
$users = DB::table('blogs')->select('id')->where('name', '=', $username)->get();
$newcomment = [];
for($i = 0 ; $i<sizeof($users) ; $i++){
for($j=0;$j<sizeof($commment);$j++){
if($users[$i]->id == $commment[$j]['blog_id']){
array_push($newcomment , $commment[$j]);
}
}
}
}
return view('dashboard.dash_comments',["data"=>$newcomment]);
}
function delete($id){
comment::find($id)->delete();
return redirect('/comments');
}
}