-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathblogcontroller.php
More file actions
65 lines (59 loc) · 2.08 KB
/
blogcontroller.php
File metadata and controls
65 lines (59 loc) · 2.08 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
62
63
64
65
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Session;
use Auth;
use Illuminate\Support\Facades\Storage;
use App\blog;
use App\comment;
use Illuminate\Support\Facades\DB;
class blogcontroller extends Controller
{
function add(Request $req){
$data = new blog;
if($req->hasFile('image')){
$fileName = $req->image->getClientOriginalName();
if($req->image->move(public_path('images'),$fileName)){
$data->image=$fileName;
$data->name = Auth::user()->name;
$data->title=$req->input('title');
$data->email=Auth::user()->email;
$data->content=$req->input('content');
$data->save();
return "<script>alert('Your Blog is sent for review');document.location='homepage'</script>";
}
else{
// here put code that will tell user that some error in uloading file is present and no need to carry on further tasks, exxit here
return "<script>alert('Your Blog was Not Uploaded. PLease try again!');document.location='homepage'</script>";
}
}else{
echo "not found.";
}
}
function select(){
$data=blog::all();
return view('dashboard.dash_blog',["data"=>$data]);
}
function home_select(){
$data = blog::orderBy('created_at', 'DESC')->paginate(8);
for($j = 0 ; $j<sizeof($data) ; $j++){
$comments = [];
$commentt = blog::find($data[$j]['id'])->comments;
for($i=0;$i<sizeof($commentt);$i++){
array_push($comments, $commentt[$i]);
}
$data[$j]['comments'] = $comments;
}
return view('/homepage',["data"=>$data]);
}
function update($id){
$data=blog::find($id);
$data->status='Accepted';
$data->save();
return redirect('blog');
}
function delete($id){
blog::find($id)->delete();
return redirect('/blog');
}
}