Categories
General Laravel

Laravel – Versionning your app.js

LIFE SAVER for frontend beginner developer!

Laravel – Versionning your app.js to cache bust for deploying

1 – Modify following file webpack.mix.js

mix.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css').version();

mix.version();

2 – Modify your blade

<script src="{{ env('APP_URL') }}{{ mix('js/app.js') }}"></script>

3 – you will see the following generation

<script src="https://xxxxx.raleche.com.test/js/app.js?id=a8305a8c81a6359c3c7b"></script>





#1 – Make sure the composer.json looks like this

"require": {
   "php": "^7.2",
   "fideloper/proxy": "^4.0",
   "laravel/framework": "^8.0",
   "laravel/passport": "^10.0",
   "laravel/socialite": "^5.0",
   "laravel/tinker": "^2.0",
   "laravel/ui": "^3.0",
   "predis/predis": "^1.1"
},
"require-dev": {
   "facade/ignition": "^2.3.6",
   "mockery/mockery": "^1.0",
   "nunomaduro/collision": "^5.0",
   "phpunit/phpunit": "^9"
}

#2 – if you see following issue

laravel/framework replaces illuminate/support and thus cannot coexist with it.

Remove remove illuminate/support

composer remove illuminate/support

#3 – The report, render, shouldReport, and renderForConsole methods of your application’s App\Exceptions\Handler class should accept instances of the Throwable interface instead of Exception instances: Change app/Exceptions/Handler.php as follow

<?php

namespace App\Exceptions;

use Throwable;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
   /**
    * A list of the exception types that are not reported.
    *
    * @var array
    */
   protected $dontReport = [
       //
   ];

   /**
    * A list of the inputs that are never flashed for validation exceptions.
    *
    * @var array
    */
   protected $dontFlash = [
       'password',
       'password_confirmation',
   ];

   /**
    * Report or log an exception.
    *
    * @param  \Throwable  $exception
    * @return void
    */
   public function report(Throwable $exception)
   {
       parent::report($exception);
   }

   /**
    * Render an exception into an HTTP response.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  \Throwable  $exception
    * @return \Illuminate\Http\Response
    */
   public function render($request, Throwable $exception)
   {
       return parent::render($request, $exception);
   }
}

Helper additional issue

php artisan config:clear
php artisan key:generate
php artisan config:clear
Categories
Laravel

How to send email via Laravel ?

Create Mailgun account

https://app.mailgun.com/app/dashboard

Update .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailgun.org
MAIL_PORT=587
MAIL_USERNAME=XXXXXXXXXXXXXXXXXXXXX
MAIL_PASSWORD=XXXXXXXXXXXXXXXXXXXXX

Clear Cache

php artisan config:cache

Categories
Laravel Technical

Flash Messaging With Vue

EPISODE 29 RUN TIME 13:59 • Apr 25th, 2017

https://laracasts.com/series/lets-build-a-forum-with-laravel/episodes/29

One of the most important topic a full stack developer should know. This topic will help you to quickly provide quick feedback to your customer within your application

https://forum.raleche.com

Categories
Laravel

Laravel redirect with message

Redirecting With Flashed Session Data

Redirecting to a new URL and flashing data to the session are usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create a RedirectResponse instance and flash data to the session in a single, fluent method chain:

Route::post('user/profile', function () {
    // Update the user's profile...

    return redirect('dashboard')->with('status', 'Profile updated!');
});

After the user is redirected, you may display the flashed message from the session. For example, using Blade syntax:

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
Categories
Laravel

Laravel Generate Authentication Page

It is very easy to generate authentication page with laravel. All you have to do is to execute the following commands

composer require laravel/ui 
php artisan ui vue --auth

And you will find all the view blade files within this directory

resources/views/auth
Laravel Authentication page
Laravel Authentication page composer require laravel/ui php artisan ui vue –auth

Categories
Laravel

Customize your error pages with Laravel

Easy commands to generate template error pages that Laravel is using, see below

php artisan vendor:publish –tag=laravel-errors

Categories
Laravel

How to force Laravel to return SSL connection calls ?

It has been a pretty long day as I was struggling to get a Laravel application to return SSL or HTTPS connections. I was put in this situation because the SysOp team of my company placed the laravel app behind a loadbalancer accepting SSL connections but converting these connection to HTTP.

It seems trivial but it did mess with the laravel application that relies on the incoming protocol to define login/logout url pages for instances

After messing up and discovering TrustProxies I found an easy solution with

Here is my solution , open the file app/Providers/AppServiceProvider.php

And add the following line URL::forceScheme('https');

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\URL;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
      URL::forceScheme('https');
    }
}