Image Upload Tutorial with Laravel 6.0 Or Laravel 7

Keywords :- Upload Image in Laravel 6.0 Or Laravel 7, Laravel Or Laravel 7 Image File Upload, Upload Image and Files with Validation in Laravel 6.0

Hello friends, today I will tell you through this tutorial How do you upload image files through Laravel 6.0. So we will learn step-to-step in Laravel 6.0.

Step 1: Laravel 6.0 Or Laravel 7 Install
Step 2: Create Table in Laravel 6.0 Or Laravel 7
Step 3: Create Resource Route in Laravel 6.0 Or Laravel 7
Step 4: Create Model in Laravel 6.0 Or Laravel 7
Step 5: Create Controller in Laravel 6.0 Or Laravel 7
Step 6: Create Blade Files in Laravel 6.0 Or Laravel 7

Step 1: Laravel 6.0 Or Laravel 7 Install

The first step is to install laravel 6.0. To install laravel 6.0 we first have to install the composer. If you have already installed the composer in your system or laptop. There is no need to install a composer.

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

Step 2: Create Table in Laravel 6.0

This is the third step. In this step you will be told how to create a table in laravel 6.0, it is very easy to create table in laravel 6.0. The table will create.

php artisan make:migration create_images_table --create=images

database/migrations

<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateImagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->increments('id');
$table->string('file');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('images');
}
}

after that Now you have to run this migration by following command:

php artisan migrate

Step 3: Create Route in Laravel 6.0

In this step, when we select the file, submit the data by post method in laravel 6.0. So in the web.php file, the url of post method will be given in this way. And add this url to the controller.

Route::get('image-upload', function () {
return view('image');
});
Route::post('fileupload', 'singleimageController@fileupload');

Step 4: Create Model in Laravel 6.0

Then after that we will create a database table model in laravel 6.0. To create a model we can create a model by using the laravel 6.0 command. The systax to create the model is given below.

php artisan make:model Image

app/Blog.php

<?php 
namespace App;
use Illuminate\Database\Eloquent\Model;
class Image extends Model
{
protected $fillable = [
'file'
];
}

Step 5: Create Controller in Laravel 6.0

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use Validator;
use Redirect;
use View;
class singleimageController extends Controller
{
public function fileupload(Request $request)
{
if($files=$request->file('file')){
$name=$files->getClientOriginalName();
$files->move('image',$name);
DB::table('images')->insert([
'file' => $name
]);
}
return redirect()->back()->with('message', 'Successfully Save Your Image file.');
}
}

Step 6: Create Blade Files in Laravel 6.0

In Laravel 6.0 you first create a form and take a field input type file in it. Just like the lower form has been created. You can also copy this form.

resources/views/image.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Laravel 5.8 Image File Upload</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css">
</head>
<body>
<form action="{{url('fileupload')}}" enctype="multipart/form-data" method="post">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<div class="col-md-12">
<div class="form-group">
<label for="">File Select</label>
<input required type="file" class="form-control" name="file">
</div>
</div>
<div class="col-md-6">
<div class="box-footer">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</body>
</html>
Cialis (Tadalafil) är den främsta konkurrenten till Viagra (Sildenafil) på marknaden för erektil dysfunktion. köpa Cialis i Sverige föredras av många på grund av sin längre varaktighet och anses vara det mest kostnadseffektiva varumärkesbaserade ED-läkemedlet som finns tillgängligt i Sverige. Cialis finns i två varianter: Cialis och Cialis Daily, och fyra olika doseringar: 2,5 mg, 5 mg, 10 mg och 20 mg, erbjuder Cialis också en rad olika alternativ för att passa patientens behov.