Tag Archives: laravel

Laravel project login error: the MAC is invalid

After the laravel project is deployed to the server and the database is imported successfully

Background login error:

The reason is laravel’s app_Key and encrypt() functions( Encrypt() is a helper function of laravel, which is equivalent to the short form of crypt:: encrypt()

Once used   php artisan key:generate   App regenerated_Key, the MAC is invalid exception will be reported when decrypting the desrypt() function, which is due to app_The change of key leads to the change of MAC information, and the decrypt() decryption reports an exception

 

Solution:

Method 1. Re encrypt with encrypt() and log in again in the background. OK

Method 2. Encrypt () encryption is not conducive to project migration and deployment. Adopt the suggestions of this blog post and temporarily use hash encryption

 

Laravel Error: No application encryption key has been specified.

 

If there is no. Env in the root directory of the file

1. Change the name of. Env.example and use the command copy to. Env

2

php artisan key:generate Get the password and save it to. Env automatically

3. Copy the password to config/APP

Key in PHP

 

4. Rerun, OK

In case of. Env, proceed to the second step directly

Neither. Please re-install laravel

Laravel route cannot be accessed, report 404, no query results for model

Geeks, please accept the hero post of 2021 Microsoft x Intel hacking contest>>>

Today, we encountered a problem. We configured the route in routes/web.php, but we were unable to access the route. We kept reporting 404

Route::resource('gift_packs', 'GiftPacksController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);
Route::get('gift_packs/test', 'GiftPacksController@test')->name('gift_packs.test');

Then I modify the render () method in the app/exceptions/handler.php file

public function render($request, Exception $exception)
{
    dd($exception);
    return parent::render($request, $exception);
}

Print out the exception:

No query results for model [App\Models\GiftPack].

First, through PHP artisan route:list View routing list

| Domain | Method                                 | URI                                                   | Name                            | 
|        | GET|HEAD                               | gift_packs/{gift_pack}                                | gift_packs.show                 | 
|        | DELETE                                 | gift_packs/{gift_pack}                                | gift_packs.destroy              | 
|        | PUT|PATCH                              | gift_packs/{gift_pack}                                | gift_packs.update               | 
|        | GET|HEAD                               | gift_packs/{gift_pack}/edit                           | gift_packs.edit                 | 
|        | GET|HEAD                               | gift_packs/test                                       | gift_packs.test                 |

The reason is that laravel routing access detection is from top to bottom

For the same path, gift_ packs/{gift_ Pack} and gift_ Pack/test, when we visit/Gift_ When packages/test, route gift_ packs/{gift_ Pack} has been parsed

The string ‘test’ could not get the data of the Giftpack model, so an error was reported

The solution is to modify the location of the routing configuration

Route::get('gift_packs/test', 'GiftPacksController@test')->name('gift_packs.test');
Route::resource('gift_packs', 'GiftPacksController', ['only' => ['index', 'show', 'create', 'store', 'update', 'edit', 'destroy']]);

That’s it

  

Laravel Syntax error or access violation: 1055 ‘***’ isn’t in GROUP BY

After laravel 5.3, MySQL strict mode is enabled by default ( strict )
in MySQL strict mode, and only is enabled_ FULL_ GROUP_ If the
group by field does not appear in the select statement, an error will be reported. If the strict mode is turned off, no error will be reported

The demo is as follows

public static function orders($phase) { return self::select(DB::raw("SUM(orders) as orders"),"type","users_id","name") ->groupBy("type","name") ->where("phase",$phase) ->get(); }

The following errors will appear. Of course, the contents of the * sign are different

Syntax error or access violation: 1055 '***' isn't in GROUP BY

Solutions

laravel the reason for the above error is sql_ For problems caused by mode setting, modify strict = > in config/database. PHP configuration file; False to turn off strict mode:

'mysql' => [
    'driver' => 'mysql',
    'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, 'engine' => null, ],

laravel The Mix manifest does not exist.

This is because we use the mix () method in resources/views/layouts/APP. Blade. PHP , but we haven’t run laravel mix to compile, and we can’t find the mix manifest. JSON file, so we report an error. It’s OK. Next, we’ll solve this problem

Run laravel mix

Laravel mix is a front-end task automation management tool, which uses the mode of workflow to execute the formulated tasks in turn. Mix provides a simple and fluent API that allows you to define webpack compilation tasks for your laravel applications. Mix supports many common CSS and JavaScript preprocessors, and you can easily manage front-end resources through simple calls

It’s easy to use mix. First, you need to install NPM dependency with the following command. We will use yarn to install dependency. Before that, because of the domestic network, we need to configure the installation acceleration for yarn

yarn config set registry https://registry.npm.taobao.org

using yarn to install dependencies:

yarn install

after the installation is successful, run the following command:

npm run watch-poll

watch poll will run continuously in your terminal to monitor whether the resource files in the resources Folder have changed. When the watch poll command is running, once the resource file changes, webpack will automatically recompile

When laravel is uploaded to the server, whoops, looks like something went wrong appears

1. When laravel, which can run well locally, uploads to the server, this problem appears: “whoops, looks like something wet wrong.”

2. Step one/ app.php ‘debug ‘= &> env (‘app’) in file_ Debug ‘, false), change to’ debug ‘= &> env (‘app’)_ DEBUG’, true),

3. A lot of information is displayed now

We notice that no supported encryption found.The Cipher and/or key length are invalid_ Copy the key value and modify it/ app.php Inside

‘key’ =&> env(‘APP_ KEY’,’base64:R+8tyPpcbK6ELMheXa4D8hsxdVvXDilVUSFCFqaH8vY=’),

This app_ Key can also be accessed through PHP artisan key:generate Generation

Now report another mistake

The description here is database connection error, modify config/ database.php File database connection problem ‘MySQL’ = & gt[

‘driver’ =&> ‘mysql’,

‘host’ =&> env(‘DB_ HOST’, ‘localhost’),

‘port’ =&> env(‘DB_ PORT’, ‘3306’),

‘database’ =&> env(‘DB_ DATABASE’, ‘forge’),

‘username’ =&> env(‘DB_ USERNAME’, ‘forge’),

‘password’ =&> env(‘DB_ PASSWORD’, ”),

‘charset’ =&> ‘utf8’,

‘collation’ =&> ‘utf8_ unicode_ ci’,

‘prefix’ =&> ‘pty_ ‘,

‘strict’ =&> false,

‘engine’ =&> null,

],

Modify the corresponding database configuration

5. There is no problem when logging in to the background administrator, but an error is reported when logging in to the added administrator

This problem is a cache problem. Modify the config/ cache.php File, put ‘default’ = &> env (‘cache ‘)_ Driver ‘,’File’), change to

‘default’ =&> env(‘CACHE_ DRIVER’, ‘array’),

This is because this error occurred when adding roles using the zizaco/enter permission package.

Need to communicate with small partners can click here to add my QQ: Luke