Sean Wade

Sean Wade

1568883995

How to create flash message notification in Laravel 6

We will define various type of flash message notification like alert success, alert danger, alert info, alert warning messages in bootstrap Laravel 6 projects. When you have success task on controller method then you can use success flash message, if you have any error task then you can use error flash message.

Flash messages are required in Laravel 6 application because that way we can give alter with what progress complete, error, warning etc. In this tutorial, I added several ways to give a flash message like redirect with success message, redirect with an error message, redirect with a warning message and redirect with info message. In this example, we use a bootstrap flash alert layout that way it becomes good layout.

So, you have to just follow the basic three step to integrate flash message in your Laravel 6 application. So let's follow below step:

Step 1: Create Global File For Flash Message

In first step we will create new blade file flash-message.blade.php. In this file we will write code of bootstrap alert and check which messages come.

There are following alert will added:

1) success

2) error

3) warning

4) info

5) validation error

So, let's create flash-message.blade.php file and put bellow code on that file.

resources/views/flash-message.blade.php

@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
    <button type="button" class="close" data-dismiss="alert">×</button>    
    <strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘error’))
<div class=“alert alert-danger alert-block”>
<button type=“button” class=“close” data-dismiss=“alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘warning’))
<div class=“alert alert-warning alert-block”>
<button type=“button” class=“close” data-dismiss=“alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($message = Session::get(‘info’))
<div class=“alert alert-info alert-block”>
<button type=“button” class=“close” data-dismiss=“alert”>×</button>
<strong>{{ $message }}</strong>
</div>
@endif

@if ($errors->any())
<div class=“alert alert-danger”>
<button type=“button” class=“close” data-dismiss=“alert”>×</button>
Please check the form below for errors
</div>
@endif

Step 2: Use Flash Message in Theme

In this step we have to just include flash-message.blade.php file in your theme default file. You have to just include this flash file in your default theme blade file like as bellow:

@include(‘flash-message’)

You can also see i added flash file on my theme, so you can add that way. Let’s see bellow example:

resources/views/layouts/app.blade.php

<!DOCTYPE html>
<html lang=“en”>
<head>
<meta charset=“utf-8”>
<meta http-equiv=“X-UA-Compatible” content=“IE=edge”>
<meta name=“viewport” content=“width=device-width, initial-scale=1”>
<!-- Styles -->
<link href=“/css/app.css” rel=“stylesheet”>
</head>
<body>

&lt;div id="app"&gt;
    @include('flash-message')

    @yield('content')
&lt;/div&gt;

&lt;!-- Scripts --&gt;
&lt;script src="/js/app.js"&gt;&lt;/script&gt;

</body>
</html>

Read Also: Laravel 6 CRUD Application Tutorial

Step 3: Use Flash Messages with Redirect

In this step we will learn how to give message when you redirect one by one:

1. Redirect with success message

We can simple redirect route or redirect url or redirect back with success flash message, we can use in controller like this way:

public function create(Request $request)
{
$this->validate($request,[
‘title’ => ‘required’,
‘details’ => ‘required’
]);

$items = Item::create($request-&gt;all());

return back()-&gt;with('success','Item created successfully!');

}

You can get layout of success flash message:

2. Redirect with error message

We can simple redirect route or redirect url or redirect back with error flash message, we can use in controller like this way:

public function create(Request $request)
{
return redirect()->route(‘home’)
->with(‘error’,‘You have no permission for this page!’);
}

You can get layout of error flash message:

3. Redirect with warning message

We can simple redirect route or redirect url or redirect back with warning flash message, we can use in controller like this way:

public function create(Request $request)
{
return redirect()->route(‘home’)
->with(‘warning’,“Don’t Open this link”);
}

You can get layout of warning flash message:

4. Redirect with info message

We can simple redirect route or redirect url or redirect back with info flash message, we can use in controller like this way:

public function create(Request $request)
{
$this->validate($request,[
‘title’ => ‘required’,
‘details’ => ‘required’
]);

$items = Item::create($request-&gt;all());

return back()-&gt;with('info','You added new items, follow next step!');

}

You can get layout of info flash message:

5. Validation Error

If you use Laravel 5 validation then you will redirect back with errors automatically, At that time it will also generate error flash message.

Read Also: Laravel 6 Ajax Request Example

public function create(Request $request)
{
$this->validate($request,[
‘title’ => ‘required’,
‘details’ => ‘required’
]);

.....

}

You can get layout of error flash message:

This way you can simple implement flash message in your Laravel 6 application.

I hope it can help you…

Originally published at https://itsolutionstuff.com

#laravel #php #web-development

What is GEEK

Buddha Community

How to create flash message notification in Laravel 6

I am Developer

1597647163

Laravel 7/6 Create Thumbnail from Image | Intervention Image Thumbnail

Laravel create thumbnail from image. Here, i will show you how to upload image and create thumbnail of uploaded image in laravel using intervention package.

Also using laravel intervention image thumbnai, you can resize the image size in laravel.

Laravel intervention image upload with Thumbnail and save to storage

  1. Install Laravel App
  2. Setup Database
  3. Install laravel intervention image thumbnail
  4. Generate migration file and model
  5. Make Route For Save and Display Image And Thumbnail
  6. Create Controller For Store Image & Thumbnail
  7. Create Blade View
  8. Make Folder
  9. Start Development Server

https://www.tutsmake.com/laravel-intervention-image-upload-using-ajax/

#laravel intervention image thumbnail #laravel create thumbnail from image #create thumbnail of image laravel 7/6 #laravel 7. x and 6. x - image upload with create thumbnail image

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

1597559012

Multiple File Upload in Laravel 7, 6

in this post, i will show you easy steps for multiple file upload in laravel 7, 6.

As well as how to validate file type, size before uploading to database in laravel.

Laravel 7/6 Multiple File Upload

You can easily upload multiple file with validation in laravel application using the following steps:

  1. Download Laravel Fresh New Setup
  2. Setup Database Credentials
  3. Generate Migration & Model For File
  4. Make Route For File uploading
  5. Create File Controller & Methods
  6. Create Multiple File Blade View
  7. Run Development Server

https://www.tutsmake.com/laravel-6-multiple-file-upload-with-validation-example/

#laravel multiple file upload validation #multiple file upload in laravel 7 #multiple file upload in laravel 6 #upload multiple files laravel 7 #upload multiple files in laravel 6 #upload multiple files php 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

I am Developer

1597727551

Laravel 7 Crud using Datatables

yajra datatables crud with ajax in laravel 7. In this post, i will show you how to create crud using datatable in laravel with ajax and model.

Now, i am going to show you how to install and use datatables in laravel 7 application. i will use jquery ajax crud with modals using datatables js in laravel 7. i will write easy code of jquery ajax request for crud with yajra datatable.

Laravel 7 DataTable CRUD Example

Use the below steps and create yajra DataTables crud with ajax in laravel:

Step 1: Install Laravel App For DataTable Crud
Step 2: Configuration .evn file
Step 3: Run Migration
Step 4: Install Yajra DataTables Package
Step 5: Add Fake Data into Database table
Step 6: Add Datatable Ajax Route
Stpe 7: Create DataTableController
Step 8: Create Ajax Datatable Blade View
Step 9: Start Development Server

https://www.tutsmake.com/laravel-7-6-install-yajra-datatables-example-tutorial/

#laravel 6 yajra datatables #yajra datatables laravel 6 example #laravel-datatables crud #yajra datatables laravel 7 #laravel 7 datatables #yajra datatables laravel