We are performing crud opertion using quiry builder in laravel
STEP : 1
Create Laravel project by running this command in terminal
CMND :– Laravel new project_name
STEP : 2
Open xammp control panel and run apache and mysql server
STEP : 3
Ceate a new database through phpmyadmin
STEP : 4
Change the database name in .env file which we have to use
STEP : 5
Creating a migration model and controller file with resources using a single line command
CMND :– php artisan make:model MODEL_NAME -mcr
here -mcr means Migration , Controller , Resouces
STEP : 6
Now serve the file by running this command
CMND :– php artisan serve
STEP : 7
Creating the table
When we run resources file its give a set of function and blueprint of the progrmme
A migratiion file is created in the migration folder with name of the controller
in this migration file we have to perform all the crud function
here i write the code for the creating a table
CODE :–
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('city');
$table->bigInteger('marks');
$table->timestamps();
});
}
STEP : 8
After this step we have to migrate this file through this command
CMND :– php artisan migrate
STEP : 9
Now we insert the value in the tabel
CODE :–
public function create(Request $request)
{
DB::table('students')->insert([
'name'=>$request->name,
'city'=>$request->city,
'marks'=>$request->marks,
]);
return redirect(route('index'))->with('status','student added ');
}
before this we have use the path of bd
use Illuminate\Support\Facades\DB;
STEP :10
Update the value
public function update(Request $request , $id)
{
DB::table('students')->where('id',$id)->update([
'name'=>$request->name,
'city'=>$request->city,
'marks'=>$request->marks,
]);
return redirect(route('index'))->with('status','student updated');
}
STEP : 11
Edit the record
public function edit($id)
{
$student=DB::table('students')->find($id);
return view('editform',['students'=>$student]);
}
STEP : 12
Deleting the record
public function destroy(Student $student)
{
DB::table('students')->where('id',$id)->delete();
}
NOTE : – Its only the execution code not a whole entire programme only the code for crud is above
To make active the code we have to make the route for the controller and return something through view .
We also have to import controller class
We have to work on the frontend where we have to make some table name the tabel and store the detail in database through tabel
THANKU.