Setup Menus in Admin Panel

  • No products in the cart.


Creating Category and News Manager

Eloquent ORM

The Eloquent ORM included with Laravel provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding “Model” which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

By default for User model is already created by laravel.

Suppose if you need to render the data from the User you have to perform the following steps:

Step 1:
Go to the directory app/Http/Admin/UserController.php and you have to define the data type as in figure below:

$data = [];
$data['rows'] = User::all();

This is for selecting all the data from the Users table.


Step 2:
For selecting the specfic data to show.

$data = [];
$data['rows'] = User::select('id', 'created_at', 'email','username','contact_no')->get();
return view('admin.user.index',compact('data'));

compact(‘data’) will assign the value of the $data.We will pass a data to view by using compact method.


You have to follow this pattern as in screenshot:



public function index()
    $data = [];
    $data['rows'] = User::select('id', 'created_at', 'email','username','contact_no','status')->get();
    return view('admin.user.index',compact('data'));


Now, we have to make the user table dynamic. So, go to the directory resources/views/admin/user/index.blade.php
and remove the table rows except one

Remove the highlighted part as in screenshot below:

and perform the foreach statement for making the table dynamic.

So go to the directory resources/views/admin/user/index.blade.php
and perform the foreach statement as:

@foreach($data['rows'] as $key => $key)




Still you have the static data. Now you have to make the data dynamic as in screenshot below:




Dashboard Screenshot:

Now making the breadboard dynamic:




Add User form:

Step 1:
Similar to user lists make the path dynamic



Step 2:
Open the form-elements.html and copy and paste the required form section to add.blade.php.



Screenshot user form



Creating category manager:
Similar to the user manager create a route path for category manager.
Step 1.Go to web.php and create a route

Route::get('category', [ 'as'=> 'category', 'uses' => 'Admin\[email protected]']);
Route::get('category/add', [ 'as'=> 'category.add', 'uses' => 'Admin\[email protected]']);
Route::post('category/store', [ 'as'=> '', 'uses' => 'Admin\[email protected]']);
Route::get('category/edit/{id}', [ 'as'=> 'category.edit', 'uses' => 'Admin\[email protected]']);
Route::post('category/update/{id}', [ 'as'=> 'category.update', 'uses' => 'Admin\[email protected]']);
Route::get('category/delete/{id}', [ 'as'=> 'category.delete', 'uses' => 'Admin\[email protected]']);

Step 2.
Go to the directory resources/views/includes/sidebar.blade.php and copy the User Manager section and paste below it for creating the category manager and change the directory.

Step 3.Creating controller class.
Go to the directory app/Http/Controller/Admin/ and Create the category controller (i.e CategoryController.php) which is similar to the UserController.php.

Step 4.Creating view for Category.
Go to the directory resources/views/admin/ then copy and paste the user folder and rename as category and give the necessary url path for category.

Step 5.
By default we had User model but for Category we have to create the model for category.
Go to the directory app and create a folder name as Models.
Now we can create a model by using the following artisan command:

php artisan make:model Models/Category




namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
protected $table = 'categories';
protected $fillable = ['title', 'slug', 'image','status'];

Screenshot for edit and store:


Submiting a form


<form action="{{ route('user/add') }}" method="POST" class="form-horizontal" role="form">     line 196


public function add(Request $request)
$this->validate($request, [
'username' => 'required',
'email' =>'required',
'contact_no' => 'required'
return view('admin.user.add');


views admin user index   line->8-10

<script type="text/javascript">
try{ace.settings.check('breadcumbs' , 'fixed')} catch (e) {}


front end validation:

for image uploading
at the end of the category/add.blade.php
add the following section


<script src="{{ asset('admin_panel/assets/js/jquery.validate.min.js') }}"></script>


For this we have to give the id name in the form section



{!! Form::open(['route' => '', 'class' =>'form-horizontal','id'=>'validation-form']) !!}

and close the form tag
{!! Form::close !!}



Now we will bind the jQuery

Creating a request

php artisan make:request Category/EditFormValidation

This command is creating a class inside “app/Http/Requests/Category” directory.


News Manager

Step 1:
Creating route

Route::get('news', [ 'as'=> 'news', 'uses' => 'Admin\[email protected]']);
Route::get('news/add', [ 'as'=> 'news.add', 'uses' => 'Admin\[email protected]']);
Route::post('news/store', [ 'as'=> '', 'uses' => 'Admin\[email protected]']);
Route::get('news/edit/{id}', [ 'as'=> 'news.edit', 'uses' => 'Admin\[email protected]']);
Route::post('news/update/{id}', [ 'as'=> 'news.update', 'uses' => 'Admin\[email protected]']);
Route::get('news/delete/{id}', [ 'as'=> 'news.delete', 'uses' => 'Admin\[email protected]']);

copy and paste CategoryController


protected $base_route = '';
protected $view_path = '';
protected $folder_name = 'news';
protected $panel = 'News';
protected $folder_path;

then create a folder name news in the directory public/images

Step 3:
Create a model for news

Step 4:
Install ckeditor

composer require unisharp/laravel-ckeditor

Creating a custom middleware:

php artisan make:middleware CustomAuth


Point the middleware:

'middleware' => 'auth-custom' to handle



namespace App\Http\Middleware;

use Closure;

class CustomAuth
* Handle an incoming request.
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
public function handle($request, Closure $next)
return $next($request);
return redirect()->route('login');
dd('in middleware..');
return $next($request);


SEE ALL Add a note
Add your Comment

Advanced Course Search Widget

Popular Courses

Course Categories

© PHPhelp. 2002 - 2018 All rights reserved.