Laravel 5 – global Blade view variable available in all templates

Option 1: You can use view::share() like so: <?php namespace App\Http\Controllers; use View; //You can create a BaseController: class BaseController extends Controller { public $variable1 = “I am Data”; public function __construct() { $variable2 = “I am Data 2”; View::share ( ‘variable1’, $this->variable1 ); View::share ( ‘variable2’, $variable2 ); View::share ( ‘variable3’, ‘I am Data … Read more

Laravel – Route::resource vs Route::controller

RESTful Resource controller A RESTful resource controller sets up some default routes for you and even names them. Route::resource(‘users’, ‘UsersController’); Gives you these named routes: Verb Path Action Route Name GET /users index users.index GET /users/create create users.create POST /users store users.store GET /users/{user} show users.show GET /users/{user}/edit edit users.edit PUT|PATCH /users/{user} update users.update DELETE … Read more

Laravel Check If Related Model Exists

In php 7.2+ you can’t use count on the relation object, so there’s no one-fits-all method for all relations. Use query method instead as @tremby provided below: $model->relation()->exists() generic solution working on all the relation types (pre php 7.2): if (count($model->relation)) { // exists } This will work for every relation since dynamic properties return … Read more

How to change public folder to public_html in laravel 5

Quite easy to find this with a simple search. See: https://laracasts.com/discuss/channels/general-discussion/where-do-you-set-public-directory-laravel-5 In your index.php add the following 3 lines. /* |————————————————————————– | Turn On The Lights |————————————————————————– | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it … Read more

How to validate array in Laravel?

Asterisk symbol (*) is used to check values in the array, not the array itself. $validator = Validator::make($request->all(), [ “names” => “required|array|min:3”, “names.*” => “required|string|distinct|min:3″, ]); In the example above: “names” must be an array with at least 3 elements, values in the “names” array must be distinct (unique) strings, at least 3 characters long. … Read more

Laravel 5.6 – Passport JWT httponly cookie SPA authentication for self consuming API?

I’ll try to answer this in a generic way so that the answer is applicable across frameworks, implementations and languages because the answers to all the questions can be derived from the general protocol or algorithm specifications. Which OAuth 2.0 grant type should I use? This is the first thing to be decided. When it … Read more

Laravel : Syntax error or access violation: 1055 Error

Short answer In config\database.php –> “mysql” array Set ‘strict’ => false to disable all. …. or You can leave ‘strict’ => true and add modes to “mysql” option in ‘mysql’ => [ … …. ‘strict’ => true, ‘modes’ => [ //’ONLY_FULL_GROUP_BY’, // Disable this to allow grouping by one column ‘STRICT_TRANS_TABLES’, ‘NO_ZERO_IN_DATE’, ‘NO_ZERO_DATE’, ‘ERROR_FOR_DIVISION_BY_ZERO’, ‘NO_AUTO_CREATE_USER’, … Read more