Wednesday, 12 July 2023

Laravel 10 setup with material ui and Laratrust.

 




Step1:  composer create-project laravel/laravel canpac

Step2:  cd canpac

Step3:  composer require laravel/ui

Step4:  php artisan ui bootstrap --auth 

Step5:  composer require laravel-frontend-presets/material-dashboard    

Step6:  php artisan ui material    

Step7:  composer dump-autoload 

Step8:  php artisan migrate 

Step9:  php artisan db:seed 

Step10: php artisan storage:link

Step11: php artisan serve

Step12: composer require santigarcor/laratrust

Step13: php artisan vendor:publish --tag=laratrust-assets --force

Step14: php artisan optimize:clear

Step15: php artisan laratrust:setup

Step16: composer dump-autoload

Step17: php artisan migrate

Step18: php artisan laratrust:seeder

Step19: php artisan vendor:publish --tag="laratrust-seeder"

Step20: composer dump-autoload

Step21: php artisan db:seed --class=LaratrustSeeder

Step22: php artisan serve

Step23: npm install

npm run dev

http://*****/laratrust/roles-assignment

******************************************************************

User Model

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Contracts\Auth\CanResetPassword;
use Laratrust\Contracts\LaratrustUser;
use Laratrust\Traits\HasRolesAndPermissions;

class User extends Authenticatable implements LaratrustUser
{
    use HasApiTokens, HasFactory, Notifiable;
    use HasRolesAndPermissions;

Web.php

<?php


use Illuminate\Support\Facades\Route;

use App\Http\Controllers\DashboardController;

use App\Http\Controllers\ProfileController;

use App\Http\Controllers\RegisterController;

use App\Http\Controllers\SessionsController;

  


Route::get('/', function () { return redirect('sign-in');})->middleware('guest');

Route::get('/dashboard', [DashboardController::class, 'index'])->middleware('auth')->name('dashboard');

Route::get('sign-up', [RegisterController::class, 'create'])->middleware('guest')->name('register');

Route::post('sign-up', [RegisterController::class, 'store'])->middleware('guest');

Route::get('sign-in', [SessionsController::class, 'create'])->middleware('guest')->name('login');

Route::post('sign-in', [SessionsController::class, 'store'])->middleware('guest');

Route::post('verify', [SessionsController::class, 'show'])->middleware('guest');

Route::post('reset-password', [SessionsController::class, 'update'])->middleware('guest')->name('password.update');

Route::get('verify', function () { return view('sessions.password.verify'); })->middleware('guest')->name('verify'); 

Route::get('/reset-password/{token}', function ($token) { return view('sessions.password.reset', ['token' => $token]); })->middleware('guest')->name('password.reset');


Route::post('sign-out', [SessionsController::class, 'destroy'])->middleware('auth')->name('logout');

Route::get('profile', [ProfileController::class, 'create'])->middleware('auth')->name('profile');

Route::post('user-profile', [ProfileController::class, 'update'])->middleware('auth');


Route::group(['middleware' => 'auth'], function () { 

Route::get('billing', function () { return view('pages.billing'); })->name('billing');

Route::get('tables', function () { return view('pages.tables'); })->name('tables');

Route::get('rtl', function () { return view('pages.rtl'); })->name('rtl');

Route::get('virtual-reality', function () { return view('pages.virtual-reality'); })->name('virtual-reality');

Route::get('notifications', function () { return view('pages.notifications'); })->name('notifications');

Route::get('static-sign-in', function () { return view('pages.static-sign-in'); })->name('static-sign-in');

Route::get('static-sign-up', function () { return view('pages.static-sign-up'); })->name('static-sign-up');

Route::get('user-management', function () { return view('pages.laravel-examples.user-management');})->name('user-management');

Route::get('user-profile', function () { return view('pages.laravel-examples.user-profile');})->name('user-profile');

});


*********************************************************************************

Laratrust->layout.blade.php

<x-layout bodyClass="g-sidenav-show bg-gray-200">

    <x-navbars.sidebar activePage="roles-permissions"></x-navbars.sidebar>

    <div class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">

        <!-- Navbar -->

        <x-navbars.navs.auth titlePage="Roles and Permissions"></x-navbars.navs.auth>

        <!-- End Navbar -->

        <link href="{{ mix('laratrust.css', 'vendor/laratrust') }}" rel="stylesheet">

        <script src="https://cdn.jsdelivr.net/gh/alpinejs/alpine@v2.x.x/dist/alpine.min.js" defer> </script>

        <div class="container-fluid py-4">

            <div class="row">

                <div class="col-12">

                    <div class="card my-4">

                        <div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">

                            <div class="bg-gradient-primary shadow-primary border-radius-lg pt-4 pb-3">

                                <div class="flex items-center justify-center h-16">

                                    <div class="flex items-center">

                                        <div class="flex items-baseline">

                                            <a href="{{config('laratrust.panel.go_back_route')}}" class="nav-button">←

                                                Go Back</a>

                                            <a href="{{ route('laratrust.roles-assignment.index') }}"

                                                class="ml-4 {{ request()->is('*roles-assignment*') ? 'nav-button-active' : 'nav-button' }}">

                                                Roles & Permissions Assignment

                                            </a>

                                            <a href="{{route('laratrust.roles.index')}}"

                                                class="ml-4 {{ request()->is('*roles') ? 'nav-button-active' : 'nav-button' }}">

                                                Roles

                                            </a>

                                            <a href="{{ route('laratrust.permissions.index') }}"

                                                class="ml-4 {{ request()->is('*permissions*') ? 'nav-button-active' : 'nav-button' }}">

                                                Permissions

                                            </a>

                                        </div>

                                    </div>

                                </div>

                            </div>

                        </div>


                        <div class="card-body p-3 pb-0">

                            @foreach (['error', 'warning', 'success'] as $msg)

                            @if(Session::has('laratrust-' . $msg))

                            <div class="alert alert-{{ $msg }} alert-dismissible text-white" role="alert">

                                <span class="text-sm">{{ Session::get('laratrust-' . $msg) }}</span>

                                <button type="button" class="btn-close text-lg py-3 opacity-10" data-bs-dismiss="alert"

                                    aria-label="Close"><span aria-hidden="true">&times;</span>

                                </button>

                            </div>

                            @endif

                            @endforeach

                        </div>


                        <div class="card-body px-0 pb-2">

                            @yield('content')

                        </div>

                    </div>

                </div>

            </div>

        </div>


        <x-footers.auth></x-footers.auth>

    </div>

    <x-plugins></x-plugins>

</x-layout>

**********************************************************

Laratrust->permission->index.blade.php

@extends('laratrust::panel.layout')

@section('title', 'Permissions')

@section('content')

@if (config('laratrust.panel.create_permissions'))

<div class=" me-3 my-3 text-end">

    <a href="{{route('laratrust.permissions.create')}}" class="btn bg-gradient-dark mb-0">+ New Permission</a>

</div>

@endif


<div class="table-responsive p-0">

    <table class="table align-items-center mb-0">

        <thead>

            <tr>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Id</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Name/Code</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Display Name</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Description</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7"></th>

            </tr>

        </thead>

        <tbody>

            @foreach ($permissions as $permission)

            <tr>

                <td>

                    <div class="d-flex px-2 py-1">

                        <div class="d-flex flex-column justify-content-center">

                            <p class="mb-0 text-sm">{{$permission->getKey()}}</p>

                        </div>

                    </div>

                </td>

                <td>

                    <div class="d-flex flex-column justify-content-center">

                        <h6 class="mb-0 text-sm">{{$permission->name}}</h6>

                    </div>

                </td>

                <td>

                    <div class="d-flex flex-column justify-content-center">

                        <h6 class="mb-0 text-sm">{{$permission->display_name}}</h6>

                    </div>

                </td>

                <td>

                    <p class="text-xs text-secondary mb-0">{{$permission->description}}</p>

                </td>

                <td class="align-middle">

                    <a rel="tooltip" class="btn btn-success btn-link" href="{{route('laratrust.permissions.edit', $permission->getKey())}}" data-original-title="" title="">

                        <i class="material-icons">edit</i>

                        <div class="ripple-container"></div>

                    </a>                    

                </td>

            </tr>

            @endforeach

        </tbody>

    </table>

</div>

{{ $permissions->links('laratrust::panel.pagination') }}

@endsection

*********************************************************************

Laratrust->Role->index.blade

@extends('laratrust::panel.layout')

@section('title', 'Roles')

@section('content')

@if (config('laratrust.panel.create_permissions'))

<div class=" me-3 my-3 text-end">

    <a href="{{route('laratrust.roles.create')}}" class="btn bg-gradient-dark mb-0">+ New Role</a>

</div>

@endif


<div class="table-responsive p-0">

    <table class="table align-items-center mb-0">

        <thead>

            <tr>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Id</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Name/Code</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Display Name</th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Description Permission

                </th>

                <th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7"></th>

            </tr>

        </thead>

        <tbody>

            @foreach ($roles as $role)

            <tr>

                <td>

                    <div class="d-flex px-2 py-1">

                        <div class="d-flex flex-column justify-content-center">

                            <p class="mb-0 text-sm">{{$role->getKey()}}</p>

                        </div>

                    </div>

                </td>

                <td>

                    <div class="d-flex flex-column justify-content-center">

                        <h6 class="mb-0 text-sm">{{$role->name}}</h6>

                    </div>

                </td>

                <td>

                    <div class="d-flex flex-column justify-content-center">

                        <h6 class="mb-0 text-sm">{{$role->display_name}}</h6>

                    </div>

                </td>

                <td>

                    <p class="text-xs text-secondary mb-0">

                        {{$role->description}} ({{$role->permissions_count}})</p>

                </td>


                <td class="justify-content-center" style="display:flex ">

                   

                        @if (\Laratrust\Helper::roleIsEditable($role))

                        <a rel="tooltip" class="btn btn-success btn-link"

                            href="{{route('laratrust.roles.edit', $role->getKey())}}">Edit</a> &nbsp;&nbsp;


                        <form action="{{route('laratrust.roles.destroy', $role->getKey())}}" method="POST"

                            onsubmit="return confirm('Are you sure you want to delete the record?');">

                            @method('DELETE')

                            @csrf

                            <button type="submit" class="btn btn-danger btn-link" data-original-title="" title="">

                                <i class="material-icons">close</i>

                                <div class="ripple-container"></div>

                            </button>

                        </form> 

                        @else

                        <a rel="tooltip" class="btn btn-success btn-link" href="{{route('laratrust.roles.show', $role->getKey())}}">Details</a>

                        @endif

                </td>

            </tr>

            @endforeach

        </tbody>

    </table>

</div> 

{{ $roles->links('laratrust::panel.pagination') }}

@endsection




No comments:

Post a Comment

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...