-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c95a01
commit 5988bfd
Showing
49 changed files
with
1,825 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Category extends Model | ||
{ | ||
protected $guarded = ['id']; | ||
|
||
public function posts() | ||
{ | ||
return $this->belongsToMany('App\Post')->withTimestamps(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Category; | ||
use App\Http\Requests\CategoryFormRequest; | ||
|
||
class CategoriesController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$categories = Category::all(); | ||
return view('backend.categories.index', compact('categories')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
return view('backend.categories.create'); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(CategoryFormRequest $request) | ||
{ | ||
$category = new Category(array( | ||
'name' => $request->get('name'), | ||
)); | ||
|
||
$category->save(); | ||
|
||
return redirect('/admin/categories/create')->with('status', 'A new category has been created!'); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit($id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(Request $request, $id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
|
||
class PagesController extends Controller | ||
{ | ||
public function home() | ||
{ | ||
return view('backend.home'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Category; | ||
use App\Post; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Support\Facades\Auth; | ||
use App\Http\Requests\PostFormRequest; | ||
use App\Http\Requests\PostEditFormRequest; | ||
|
||
class PostsController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$posts = Post::all(); | ||
return view('backend.posts.index', compact('posts')); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
$categories = Category::all(); | ||
return view('backend.posts.create', compact('categories')); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(PostFormRequest $request) | ||
{ | ||
$user_id = Auth::user()->id; | ||
$post= new Post(array( | ||
'title' => $request->get('title'), | ||
'content' => $request->get('content'), | ||
'slug' => Str::slug($request->get('title'), '-'), | ||
'user_id' => $user_id | ||
)); | ||
|
||
$post->save(); | ||
$post->categories()->sync($request->get('categories')); | ||
|
||
return redirect('/admin/posts/create')->with('status', 'The post has been created!'); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show($id) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit($id) | ||
{ | ||
$post = Post::whereId($id)->firstOrFail(); | ||
$categories = Category::all(); | ||
$selectedCategories = $post->categories->pluck('id')->toArray(); | ||
return view('backend.posts.edit', compact('post', 'categories', 'selectedCategories')); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update($id, PostEditFormRequest $request) | ||
{ | ||
$post = Post::whereId($id)->firstOrFail(); | ||
$post->title = $request->get('title'); | ||
$post->content = $request->get('content'); | ||
$post->slug = Str::slug($request->get('title'), '-'); | ||
|
||
$post->save(); | ||
$post->categories()->sync($request->get('categories')); | ||
|
||
return redirect(action('Admin\PostsController@edit', $post->id))->with('status', 'The post has been updated!'); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy($id) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\RoleFormRequest; | ||
use Spatie\Permission\Models\Role; | ||
use Spatie\Permission\Models\Permission; | ||
|
||
class RolesController extends Controller | ||
{ | ||
public function create() | ||
{ | ||
return view('backend.roles.create'); | ||
} | ||
|
||
public function store(RoleFormRequest $request) | ||
{ | ||
Role::create(['name' => $request->get('name')]); | ||
|
||
return redirect('/admin/roles/create')->with('status', 'A new role has been created!'); | ||
} | ||
|
||
public function index() | ||
{ | ||
$roles = Role::all(); | ||
return view('backend.roles.index', compact('roles')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use Illuminate\Http\Request; | ||
use App\Http\Controllers\Controller; | ||
use App\User; | ||
use Spatie\Permission\Models\Role; | ||
use App\Http\Requests\UserEditFormRequest; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UsersController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$users = User::all(); | ||
return view('backend.users.index', compact('users')); | ||
} | ||
|
||
public function edit($id) | ||
{ | ||
$user = User::whereId($id)->firstOrFail(); | ||
$roles = Role::all(); | ||
$selectedRoles = $user->roles()->pluck('name')->toArray(); | ||
return view('backend.users.edit', compact('user', 'roles', 'selectedRoles')); | ||
} | ||
|
||
public function update($id, UserEditFormRequest $request) | ||
{ | ||
$user = User::whereId($id)->firstOrFail(); | ||
$user->name = $request->get('name'); | ||
$user->email = $request->get('email'); | ||
$password = $request->get('password'); | ||
if($password != "") { | ||
$user->password = Hash::make($password); | ||
} | ||
$user->save(); | ||
|
||
$user->syncRoles($request->get('role')); | ||
|
||
return redirect(action('Admin\UsersController@edit', $user->id))->with('status', 'The user has been updated!'); | ||
} | ||
} |
Oops, something went wrong.