CRUD Flashcards
Get All In laravel
$posts= DB::table('posts')->get(); // foreach ($posts as $post){ // echo $post->title; // }
Insert in laravel
soft delete
In Model class file class User{ use SoftDeletes; } IN Migration file $table->softDeletes( );
get soft delete data
$users = User::onlyTrashed( )->latest( );
Insert Data With Query Builder
use Illumiante/facades/DB
public function store( ) {
$data -> array( );
$data[“name”] = $request ->name;
$data[“user_id”] = Auth::user( )->id;
DB::table( “users”)->insert($data );
}
Query Builder update and edit
get single data first
$category =DB::table(‘categories’)->where(‘id’,$id)->first( );
$data -> array( );
$data[“name”] = $request ->name;
$data[“user_id”] = Auth::user( )->id;
DB::table( “users”)->where(‘id’,$id)->update($data );
restore data and permanant delete
public function Restore($id){
$delete = User::withTrashed( )->find($id)->restore()
}
$delete = User::onlyTrashed( )->find($id)->forceDelete()