Tagged: 5

laravel checking if record exists 0

laravel checking if record exists

Today, We want to share with you laravel checking if record exists.In this post we will show you check if row exists laravel, hear for How to check if record exists or not in Laravel 5? we will give you demo and example for implement.In this post, we will learn about laravel validation check if exists in database with an example.

laravel checking if record exists

There are the Following The simple About laravel checking if record exists Full Information With Example and source code.

As I will cover this Post with live Working example to develop check object null in laravel, so the some check if record exists in laravel for this example is following below.

$product = Products::where('status', ‘=’, Input::get('status'))->first();
if ($product === null) {
// product doesn’t exist
}

And if you only want to check

if (Products::where('status', ‘=’, Input::get('status'))->count() > 0) {
// product found
}

Or even nicer

if (Products::where('status', ‘=’, Input::get('status'))->exists()) {
// product found
}

How to check if record exists or not in Laravel 5?

$product = Product::where('pcode',Input::get('pcode'))->first();
if (is_null($product)) {
   print_r("pcode is exists");
}

   print_r("pcode is not exists");

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about checking if record exists.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

global variable for all controller and views in Laravel 0

global variable for all controller and views in Laravel

Today, We want to share with you global variable for all controller and views in Laravel.In this post we will show you set global dynamic variables in Laravel 5.8, hear for Laravel define global constants Config php file we will give you demo and example for implement.In this post, we will learn about How to set a variable inside Laravel’s blade template with an example.

global variable for all controller and views in Laravel

There are the Following The simple About global variable for all controller and views in Laravel Full Information With Example and source code.

As I will cover this Post with live Working example to develop How to define Global Variables in Laravel 5.8?, so the Laravel 5.8 – global and dynamic variable for this example is following below.

How to create global variable in laravel 5.6?

config/global.php

set simple your array here.

return [
  'website_title' => 'pakainfo Blog',
  'pagination' => 10,
  'tagLine' => 'Welcome to pakainfo website Love You',
  'API_KEY' => 'hjh566s5df$#FDsf45f4df7ds8ds',
];

Use in your laravel blade view file.

{{ config('global.website_title') }}

{{ config('global.tagLine') }}

Web Programming Tutorials Example with Demo

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about global variable for all controller and views in Laravel.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

How to get last record from MySQL table in Laravel? 0

How to get last record from MySQL table in Laravel

Today, We want to share with you How to get last record from MySQL table in Laravel?.In this post we will show you Get latest row of table in model, hear for How to get last record of database table in Laravel? we will give you demo and example for implement.In this post, we will learn about How to get last record from table in PHP Laravel Framework with an example.

How to get last record from MySQL table in Laravel?

There are the Following The simple About How to get last record from MySQL table in Laravel? Full Information With Example and source code.

As I will cover this Post with live Working example to develop laravel – Select Last Row in the Table, so the some Select Last Row in the Table for this example is following below.

Using latest() belong to created_at field: Laravel

$products = DB::table('products')->latest()->first();
dd($products);

Using orderBy() belong to id field: Laravel

$products2 = DB::table('products')->orderBy('id', 'DESC')->first();
dd($products2);

Using latest() in Laravel belong to id field:

$products3 = DB::table('products')->latest('id')->first();
dd($products3);

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to get last record from MySQL table in Laravel?.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

File upload size validation using Laravel 5.7 0

File upload size validation using Laravel 5.7

Today, We want to share with you File upload size validation using Laravel 5.7.In this post we will show you Laravel 5.7 max file size validation for file/image fields, hear for Check (Validate) File Size before upload using Laravel we will give you demo and example for implement.In this post, we will learn about How to validate upload file size and file extension using Laravel 5.7 with an example.

File upload size validation using Laravel 5.7

There are the Following The simple About File upload size validation using Laravel 5.7 Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.7 File upload size validation using jQuery with demo, so the Laravel 5.7 file upload size validation for this example is following below.

Validate Max File Size in Laravel

[
  'image' => 'required|mimes:jpeg,bmp,png|size:20000',
]

Your File size should be not more than 20 MB (20000 kB).

According to the Laravel 5.7 documentation:

$validator = Validator::make($request->all(), [
    'file' => 'max:500000',
]);

The value is in kilobytes. I.e. max:10240 = max 10 MB.

You Can Also Read step By step My Tiny Post Forlaravel 5.7 crud

Example 1: Laravel File Size Validation

app/Http/Controllers/ImageUploadController.php

public function imagePostUpload()
{
    request()->validate([
        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
    ]);
    $imgFlName = time().'.'.request()->image->getClientOriginalExtension();
    request()->image->move(public_path('images'), $imgFlName);
    return back()
        ->with('success','You have successfully upload files/image.')
        ->with('image',$imgFlName);
}

Example 2: Laravel Image Upload Validation

    public function imagePostUpload(Request $req)
    {
        $this->validate($req, [
            'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);

        $image = $req->file('image');
        $input['flimgname'] = time().'.'.$image->getClientOriginalExtension();
        $uploadPath = public_path('/images');
        $image->move($uploadPath, $input['flimgname']);


        $this->postImage->add($input);
        return back()->with('success','Image Upload successful');
      }

You Can Also Read step By step My Tiny Post Forupload image in laravel 5.7

Laravel 5.7 – image dimension validation rules examples

There are the Following List of the laravel image dimension validation

$this->validate($request, [
    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:width=500,height=500',
]);

$this->validate($request, [
    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:min_width=350,min_height=600',
]);

$this->validate($request, [
    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:max_width=350,max_height=600',
]);

$this->validate($request, [
    'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048|dimensions:ratio=3/2',
]);

You Can Also Read step By step My Tiny Post Forlaravel activity log

Angular 6 CRUD Operations Application Tutorials

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about File upload size validation using Laravel 5.7.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.