Posts

Showing posts with the label laravel

laravel raw query generator

    $query = User :: where ([ 'dept_id' => $request -> dept_id , 'role' => 'emp' ]);         $sql = $query -> toSql ();         $bindings = $query -> getBindings ();         $sqlWithBindings = Str :: replaceArray ( '?' , $bindings , $sql );         dd ( $sqlWithBindings );

Laravel Auth Registration and Login with Bootstrap

  composer require laravel/ui php artisan ui bootstrap php artisan ui bootstrap --auth npm install npm run dev npm run production

How to disable CSRF Token in Laravel and why we have to disable it?

Image
  You can Disable CSRF on few routes by editing. App\Http\Middleware\VerifyCsrfToken and add your own routes name in protected  Disable for all routes protected $except = [ '*' , ]; Disable for some routes protected $except = [ 'mobile/*' , 'news/articles' , ];

Steps after get cloned from github Laravel Project

Image
  Clone your project . Go to the folder application using cd command on your cmd or terminal. Run composer install on your cmd or terminal. Copy .env.example file to .env on the root folder. ... Open your project Run php artisan key:generate. Run php artisan migrate. Run php artisan serve.

Laravel 8 Accessor and Mutator in Hindi | Laravel Tutorial

Image

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

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

Image

Send an Email with attachment from Laravel 8 using PHPmailer Library | 2...

Image

Laravel 8.x CRUD (Create,Read,Update and Delete) Operation using Query B...

Image

Dynamic number of rows in Laravel Blade

Image
  This is correct: @ foreach ( $collection as $index => $element ) {{ $index }} - {{ $element [ 'name' ]}} @ endforeach And you must use index+1 because index starts from 0. Using raw PHP in view is not the best solution. Example: <tbody> <?php $i = 1 ; @ foreach ( $aaa as $value ) ?> <tr> <td> <?php echo $i ; ?> </td> <td> <?php {{ $value ->name}}; ?> </td> </tr> <?php $i ++; ?> <?php @ endforeach ?> <thead> <th>number</th> <th>name</th> </thead> <tbody> @ foreach ( $aaa as $index => $value ) <tr> <td>{{ $index }}</td> // index +1 to begin from 1 <td>{{ $value }}</td> </tr> @ endforeach </tbody> ...

Custom Registration and Login using Eloquent with Session in Laravel La...

Image

Put request in POSTMAN, laravel

 For PUT calls, try adding data in   x-www-form-urlencoded