How To Create Custom 404 Page In Laravel

Many of you are really sick of seeing standard 404 pages or **Sorry! Page your look for not found. **Here is a really simple way where you can create a custom tailored one with Laravel.

Prerequisites

I hope you have a fresh installation of Laravel or existing Laravel application. If you dont know how to install Laravel then use the following composer command to get started with.

composer create-project --prefer-dist laravel/laravel blog

Make sure to be updated with the latest stable version of Laravel. The above command installs latest version of **Laravel**


Step 1 - Add Fallback URL

First and the foremost thing in this step is to add Fallback URL in **web.php** file and **api.php** file

**Add in the end of your ****web.php** & **api.php** file. As you can see below that I am directly calling 404 from fallback route.

/** Fallback Route */
Route::fallback(function () {
    /** This will check for the 404 view page unders /resources/views/errors/404 route */
    return view('errors.404');
});

Step 2 - Custom HTML 404 Blade File

Now create 404.blade.php file inside /resources/views/errors/ folder. You can add any image or text you need, mine looks like the following

@extends('layouts.master')
@section('content')
    <br><br>
    <div class="row">
        <div class="col-md-12 text-center">
            <h3>Oops! Article not found.</h3> <br>
            <h2><a href="{{ url('/') }}"><span class="text-underline">Try Here!</span> Get some fresh ones.</a></h2>
        </div>
    </div>
    <br><br>
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <img src="{{ asset('images/404.svg?cb='.env('CB_VERSION')) }}" alt="404 Image" class="width100">
        </div>
    </div>
@endsection

#laravel #custom #404

What is GEEK

Buddha Community

How To Create Custom 404 Page In Laravel

Laravel 8 Create Custom Helper Function Example

Today, We will see laravel 8 create custom helper function example, as we all know laravel provides many ready mate function in their framework, but many times we need to require our own customized function to use in our project that time we need to create custom helper function, So, here i am show you custom helper function example in laravel 8.

Laravel 8 Create Custom Helper Function Example

https://websolutionstuff.com/post/laravel-8-create-custom-helper-function-example


Read Also : Cron Job Scheduling In Laravel

https://websolutionstuff.com/post/cron-job-scheduling-in-laravel

#laravel 8 create custom helper function example #laravel #custom helper function #how to create custom helper in laravel 8 #laravel helper functions #custom helper functions in laravel

How To Create Custom 404 Page In Laravel

Many of you are really sick of seeing standard 404 pages or **Sorry! Page your look for not found. **Here is a really simple way where you can create a custom tailored one with Laravel.

Prerequisites

I hope you have a fresh installation of Laravel or existing Laravel application. If you dont know how to install Laravel then use the following composer command to get started with.

composer create-project --prefer-dist laravel/laravel blog

Make sure to be updated with the latest stable version of Laravel. The above command installs latest version of **Laravel**


Step 1 - Add Fallback URL

First and the foremost thing in this step is to add Fallback URL in **web.php** file and **api.php** file

**Add in the end of your ****web.php** & **api.php** file. As you can see below that I am directly calling 404 from fallback route.

/** Fallback Route */
Route::fallback(function () {
    /** This will check for the 404 view page unders /resources/views/errors/404 route */
    return view('errors.404');
});

Step 2 - Custom HTML 404 Blade File

Now create 404.blade.php file inside /resources/views/errors/ folder. You can add any image or text you need, mine looks like the following

@extends('layouts.master')
@section('content')
    <br><br>
    <div class="row">
        <div class="col-md-12 text-center">
            <h3>Oops! Article not found.</h3> <br>
            <h2><a href="{{ url('/') }}"><span class="text-underline">Try Here!</span> Get some fresh ones.</a></h2>
        </div>
    </div>
    <br><br>
    <div class="row">
        <div class="col-md-6 col-md-offset-3">
            <img src="{{ asset('images/404.svg?cb='.env('CB_VERSION')) }}" alt="404 Image" class="width100">
        </div>
    </div>
@endsection

#laravel #custom #404

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

I am Developer

1604492424

Laravel 8 Custom Validation Error Messages Example

Laravel 8 custom validation rules and error messages. In this tutorial, i will show you how to add custom validation rules and display custom validation error messages in laravel 8 app.

Laravel 8 Custom Validation Rule & Error Message Example

  • Step 1 - Install Laravel 8 App
  • Step 2 - Connecting App to Database
  • Step 3 - Run Migration Command
  • Step 4 - Add Routes
  • Step 5 - Generate Controller By Command
  • Step 6 - Create the blade view
  • Step 7 - Run Development Server

https://www.tutsmake.com/laravel-8-custom-validation-error-messages-tutorial/

#laravel custom validation rule with parameters #laravel custom validation message #laravel request validation custom message #laravel custom validation error messages

Seamus  Quitzon

Seamus Quitzon

1595216280

Some of the most frequent how tos in Laravel

How to get relationship from relationship using With() in Laravel

Some times there are cases where you want to get relationship from relationship in Laravel, that can be achieved via following:

Account::with(['profiles','profiles.products'])->get();

How to create multiple where clauses in single where clause in Laravel

Sometimes you want to apply multiple where clauses in a single query like that:

$results = User::where('this', '=', 1)
    ->where('that', '=', 1)
    ->where('this_too', '=', 1)
    ->where('that_too', '=', 1)
    ->where('this_as_well', '=', 1)
    ->where('that_as_well', '=', 1)
    ->where('this_one_too', '=', 1)
    ->where('that_one_too', '=', 1)
    ->where('this_one_as_well', '=', 1)
    ->where('that_one_as_well', '=', 1)
    ->get();

This can be achieved using single where clause by following code:

$query->where([
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE]
])

How to get last inserted id in Laravel

The are situations, during bulk insertion or single row insertion you may want to retrieve last inserted id, can be achieved by following:

$post = Input::All();

    $data = new Company;
    $data->nombre = $post['name'];
    $data->direccion = $post['address'];
    $data->telefono = $post['phone'];
    $data->email = $post['email'];
    $data->giro = $post['type'];
    $data->fecha_registro = date("Y-m-d H:i:s");
    $data->fecha_modificacion = date("Y-m-d H:i:s");
   $data->save();
   //getting last inserted id
   $data->id;

How to add a custom attribute in Laravel during Model load

Sometimes you want to add a custom attribute in model during load, this can be achieved by following code:

class Book extends Eloquent {

    protected $table = 'books';

    public function toArray()
    {
        $array = parent::toArray();
        $array['upper'] = $this->upper;
        return $array;
    }

    public function getUpperAttribute()
    {
        return strtoupper($this->title);    
    }

}

#laravel #php #how to add a custom attribute in laravel during model load #how to create multiple where clauses in single where clause in laravel #how to get a specific column using with() in laravel #how to get last inserted id in laravel #how to get relationship from relationship laravel #laravelfaq