find id laravel code example

Example 1: laravel get ID from insert

$data = User::create(['name'=>'first']);
dd($data->id);

Example 2: laravel create get id

$id = $this->create($data)->id;

Example 3: eloquent first

$user = User::where('mobile', Input::get('mobile'))->get();

if (!$user->isEmpty()){
    $firstUser = $user->first()
}

Example 4: laravel create get id

$user = User::create([
    'username' => $data['username'] . ' ' . $data['username2'],
    'mail' => $data['mail'],
    'password' => bcrypt($data['password']),
]);

$userInfo = UserInformation::create([
    'user_id' => $user->id,
    'current_food' => $food,
    'current_level' => $level,
]);

Tags:

Php Example