Answers for "laravel eloquent and where"

PHP
3

laravel soft delete

/** in migrations this changes need to
    add for table we want to add soft delete (LARAVEL)*/

	/** The migrations. START */
	public function up()
	{
		Schema::table('users', function(Blueprint $table)
		{
			$table->softDeletes();
		});
	}
	/** The migrations. END */

	/** after adding softdelete you need to
    point that column in table related model (LARAVEL)*/

	/** The Model. START */
  	use Illuminate\Database\Eloquent\SoftDeletes;
  	class User extends Model {
	  use SoftDeletes;
	  protected $dates = ['deleted_at'];
	}
	/** The Model. END */
Posted by: Guest on November-17-2020
2

laravel eloquent get first

// return first row by id
$user = App\User::where('id',$id)->first();
// or return directly a field
$userId = App\User::where(...)->pluck('id');
Posted by: Guest on May-17-2020
6

laravel create or update

// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Posted by: Guest on September-27-2020
0

laravel where in

$users = DB::table('users')->whereIn('id', array(1, 2, 3))->get()
Posted by: Guest on June-24-2021
0

where () laravel Eloquent

//los signos de igualdad pueden ser: ">=", "<=", "=", ">", "<"
$user = User::where("estado","=",1)->find(10);
Posted by: Guest on February-09-2021
0

laravel where and where

Table::where('Column', Value)->where('NewColumn', Value)->get();
Posted by: Guest on September-04-2020

Code answers related to "laravel eloquent and where"

Browse Popular Code Answers by Language