mehul bagada

mehul bagada

1581600949

how to get last inserted id in laravel 6?

In this example, i will give you simple example of how to get last inserted id in laravel 6. you can simply get laravel 6 get last inserted record id with example.

,when you create database,you many a time use primary key column using the AUTO_INCREMENT attribute that means when you insert new record into the table then value of primary key column will be auto-increment with unique integer.

Whenever you perform an INSERT or UPDATE on database table with an AUTO_INCREMENT column then you get the last insert id of last insert or update query.

In PHP, you use mysqli_insert_id to get last inserted record id.

In laravel, when you go with DB query builder then you can use insertGetId() that will insert a record and then return last inserted record id.

Link :- https://www.nicesnippets.com/blog/how-to-get-last-inserted-id-in-laravel-6

#laravel #laravel6 #laraveltutorial #laravelwebdevelopment #laraveldevelopment

What is GEEK

Buddha Community

how to get last inserted id in laravel 6?

How to Get Current URL in Laravel

In this small post we will see how to get current url in laravel, if you want to get current page url in laravel then we can use many method such type current(), full(), request(), url().

Here i will give you all example to get current page url in laravel, in this example i have used helper and function as well as so let’s start example of how to get current url id in laravel.

Read More : How to Get Current URL in Laravel

https://websolutionstuff.com/post/how-to-get-current-url-in-laravel


Read More : Laravel Signature Pad Example

https://websolutionstuff.com/post/laravel-signature-pad-example

#how to get current url in laravel #laravel get current url #get current page url in laravel #find current url in laravel #get full url in laravel #how to get current url id in laravel

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

I am Developer

1597563325

Laravel 7/6 Image Upload Example Tutorial

Laravel image upload example tutorial. Here, i will show you how to upload image in laravel 7/6 with preview and validation.

Before store image into db and folder, you can validate uploaded image by using laravel validation rules. as well as you can show preview of uploaded image in laravel.

Image Upload In Laravel 7/6 with Validation

Image upload in laravel 7/6 with preview and validation. And storage image into folder and MySQL database by using the below steps:

Install Laravel Fresh App
Setup Database Details
Generate Image Migration & Model
Create Image Upload Route
Create Image Controller
Create Image Upload and Preview Blade View
Start Development Server

https://www.tutsmake.com/laravel-7-6-image-upload-with-preview-validation-tutorial/

#laravel 7 image upload example #laravel upload image to database #how to insert image into database in laravel #laravel upload image to storage #laravel image upload tutorial #image upload in laravel 7/6

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

1608637001

Laravel 8 Get Country, City Address From IP Address

How to get country name from IP address in Laravel 8 app. In this tutorial, i will show you How to get country city state zip code metro code from IP address in Laravel 8 app.

How to get location(county,city address) information from ip address in Laravel

  • Step 1 - Install Laravel 8 App
  • Step 2 - Connecting App to Database
  • Step 3 - Install "stevebauman/location"
  • Step 4 - Add Routes
  • Step 5 - Create Controller By Command
  • Step 6 - Start Development Server

https://www.tutsmake.com/laravel-8-get-country-city-address-from-ip-address-tutorial/

#get location from ip address in laravel #laravel address from ip address #laravel get country city from ip address #laravel get user country by ip #laravel geoip to address