Results: 71
Laravel project settings by environment
Local environment settings:
APP_ENV=local
APP_DEBUG=true
Test environment settings:
APP_ENV=testing
APP_DEBUG=true
Production environment settings:
APP_ENV=production
APP_DEBUG=false
The main difference is that errors are not shown on production, also prevention mechanisms from deleting DB data using migration tools
tinyint data type
In Laravel 8+
tinyInteger
method generates
tinyint(4)
data type in MySQL
$table->tinyInteger('column_name');
Whereas
boolean
method generates
tinyint(1)
data type
$table->$table->boolean('column_name');
passing PHP values to JS in Laravel blade
Correct way to pass values to
JS
is to use
!!
directives:
<script>
        
    change_asset_category('{!! $category_values !!}');

</script>
The result will be:
<script>
        
change_asset_category('{"version":"vers","patch_level":"patc","bcp_dr":"bcp\/d"}');

</script>
key:generate
This command sets the
APP_KEY
value in our
.env file
for security purposes (for sessions and other encrypted data)
php artisan key:generate
Adds exceptions so that unauthorized users will be able to see all posts and individual post
public function __construct() {
    $this->middleware('auth', ['except'=>['index', 'show']]);
}
Only the post author will be able to edit the post
public function edit($id)
{
    $post = POST::find($id);

    // Check for correct user
    if (auth()->user()->id !== $post->user_id) {
        return redirect('/posts')->with('error', 'Unauthorized page');
    }

    return view('posts.edit')->with('post', $post);
}
It will remove devDependencies from
package.json
like
bootstrap, jquery, popper.js, vue
(removes frontend scaffolding)
php artisan preset none
Except the following packages
"devDependencies": {
    "axios": "^0.19",
    "cross-env": "^7.0",
    "laravel-mix": "^5.0.1",
    "lodash": "^4.17.19",
    "resolve-url-loader": "^3.1.0",
    "sass": "^1.15.2",
    "sass-loader": "^8.0.0"
}
Lists all the available commands
php artisan
Deletes the specified post
public function destroy($id)
{
    $post = POST::find($id);
    $post->delete();    
    return redirect('/posts')->with('success', 'Post Removed');
}
If we want to parse HTML saved by
ckeditor
we should use
{!!$post->body!!}
instead of
{{$post->body}}
Results: 71