CRUD Flashcards

1
Q

Get All In laravel

A
$posts= DB::table('posts')->get();
//      foreach ($posts as $post){
//          echo $post->title;
//      }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Insert in laravel

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

soft delete

A
In Model class file
class User{
use SoftDeletes;
}
IN Migration file
$table->softDeletes( );

get soft delete data
$users = User::onlyTrashed( )->latest( );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Insert Data With Query Builder

A

use Illumiante/facades/DB

public function store( ) {

$data -> array( );
$data[“name”] = $request ->name;
$data[“user_id”] = Auth::user( )->id;
DB::table( “users”)->insert($data );

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Query Builder update and edit

A

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 );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

restore data and permanant delete

A

public function Restore($id){
$delete = User::withTrashed( )->find($id)->restore()
}

$delete = User::onlyTrashed( )->find($id)->forceDelete()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly