Posts

Laravel 8.x Role Based Multi Auth using Laratrust | Latest 2021 | Hindi ...

Image

Laravel breez and laratrust

 composer require laravel/breeze --dev php artisan breeze:install npm install && npm run dev composer require santigarcor/laratrust php artisan vendor:publish --tag="laratrust" php artisan laratrust:setup php artisan laratrust:seeder php artisan vendor:publish --tag="laratrust-seeder" composer dump-autoload $this->call(LaratrustSeeder::class); database seeder file php artisan migrate php artisan db:seed <div class="mt-4">                 <x-label for="role_id" :value="__('Register As')" />                 <select id="role_id" class="block mt-1 w-full"                                 name="role_id" required>        ...

Laravel adding hasRole method to Auth

Image
  adding the following to your User model:- public function hasRole ( $role ) { return User::where( 'role' , $role )->get(); } This should firstly check to see if you User table has the field 'role' and then check your parameter $role against the role field. You can the check by doing the following: if ( Auth::user()->hasRole( $role ) ) You may need to adjust the example to your needs. Let me know if you need anything else. /------------EDIT-----------------/ If you have two seperate tables, one holding the user information and the other holding the users privileges/roles you could add another function to the User model: public function userID ( ) { return $this ->user_id; } This will check for if you have a user ID field if so, it will return the id for the authenticated user. Then add this to your hasRoles method: public function hasRoles ( $userID , $roles ) { return Your\User\Roles\Model::where( 'role...

Validate Max File Size in Laravel

Image
    First, let’s see how to validate file size in Laravel. In your Form Request files or validate() method you can pass array with this parameter: [ 'image' => 'required|mimes:jpeg,bmp,png|size:20000', ] The last part means that size should be not more than 20 MB (20000 kB). But that may be not enough, cause file restrictions exist not only on Laravel application level.

Laravel 8 File Upload with Custom Renaming and Helper Creation | Latest ...

Image

PHP mysql Database Backup

Image
  $date_string   = date("Ymd");  $dbhost = "localhost";     $dbuser = 'dbuser';     $dbpass = 'dbuserpass';     $dbname = 'dbname';     $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);     $backupAlert = '';     $tables = array();     $result = mysqli_query($connection, "SHOW TABLES");     if (!$result) {         $backupAlert = 'Error found.<br/>ERROR : ' . mysqli_error($connection) . 'ERROR NO :' . mysqli_errno($connection);     } else {         while ($row = mysqli_fetch_row($result)) {             $tables[] = $row[0];         }         mysqli_free_result($result);         $return = '...

Laravel 8.x Resource CRUD (Create,Read,Update,Delete) operation | 2021 ...

Image