Giter Site home page Giter Site logo

119_boolpress's Introduction

Laravel Auth

Install Laravel

# command you use to install laravel

Install Breeze

composer require laravel/breeze --dev
php artisan breeze:install

┌ Which Breeze stack would you like to install? ───────────────┐ │ Blade with Alpine │ └──────────────────────────────────────────────────────────────┘

┌ Would you like dark mode support? ───────────────────────────┐ │ No │ └──────────────────────────────────────────────────────────────┘

┌ Which testing framework do you prefer? ──────────────────────┐ │ Pest └──────────────────────────────────────────────────────────────┘

Install laravel preset package

 
 
composer require pacificdev/laravel_9_preset
# Esegui comando preset
php artisan preset:ui bootstrap --auth
npm i

Update the vite config file

mv vite.config.js vite.config.cjs

php artisan serve
npm run dev

⚡ Ricorda di committare e pushare regolarmente!

Refactoring Admin dashboard

create a controller to handle the dashboard requests

php artisan make:controller Admin/DashboardController

update the route and use the above controller

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

retun the view in the index method in the dashboard controller

class DashboardController extends Controller
{
    function index()
    {
        return view('dashboard');
    }
}

Add a route group

First create a new route group and add the following methods:

  • middleware
  • name
  • prefix
  • group
// web.php

Route::middleware(['auth', 'verified'])
    ->name('admin.')
    ->prefix('admin')
    ->group(function () {
        // All routes need to share a common name and prefix and the middleware
       // 👇
        // Put here all routes that needs to be protected by our authenticatio system


    });

Move the dashboard route insde the group create above

Route::middleware(['auth', 'verified'])
    ->name('admin.')
    ->prefix('admin')
    ->group(function () {
        // All routes need to share a common name and prefix and the middleware
       // 👇
        // Put here all routes that needs to be protected by our authenticatio system
        Route::get('/', [DashboardController::class, 'index'])->name('dashboard'); //admin


    });

Note: the dashbord route now uses only a / as the URI because it inherits the prefix from the group.

Update the constant at line 20 used in RouteServiceProvider.php from:

//RouteServiceProvider.php
public const HOME = '/dashboard';

to:

//RouteServiceProvider.php
    public const HOME = '/admin';

Add a new layout file for the admin

Copy the original app.blade.php layout file and create a new file called admin.blade.php that we will use on all admin pages including our dashboard.

cd resources/views/layouts
cp app.blade.php admin.blade.php

extend the new admin layout inside the dashboard.blade.php

@extends('layouts.admin')

@section('content')
<div class="container">
    <h2 class="fs-4 text-secondary my-4">
        {{ __('Dashboard') }}
    </h2>
    <div class="row justify-content-center">
        <div class="col">
            <div class="card">
                <div class="card-header">{{ __('User Dashboard') }}</div>

                <div class="card-body">
                    @if (session('status'))
                    <div class="alert alert-success" role="alert">
                        {{ session('status') }}
                    </div>
                    @endif

                    {{ __('You are logged in!') }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Update the dropdown link in the header navigation menu for the admin layout (around line 73~) as follow

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
  <a class="dropdown-item" href="{{ url('admin') }}">{{__('Dashboard')}}</a> // 👈 Update this link
  <a class="dropdown-item" href="{{ url('profile') }}">{{__('Profile')}}</a>
  <a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
                       document.getElementById('logout-form').submit();">
      {{ __('Logout') }}
  </a>

    <form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
        @csrf
    </form>
</div>

-> Turn the repo here in a github template repository


CRUD for posts

Now you can start working to your crud operations for the given resource

create:

  • model
  • migration
  • controller (resource)
  • seeder
  • two form requests
php artisan make:model Post -mscrR

Implement all operations

Do as usual...

119_boolpress's People

Contributors

fabiopacifici avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.