1) First u need to create table like this (php artisan make:migration create employees_table)
public function up()
{
Schema::create('_items', function (Blueprint $table) {
$table->id();
$table->string('Item_Name');
$table->string('Item_Category');
$table->integer('Price');
$table->string('image_url');
$table->string('Item_Type');
$table->timestamps();
});
2) Make Model and Controller, Model name must same like database table (php artisan make:model AdminController -mcr)
3) Create function in controller to add the form data into database like this.
public function add(Request $request)
{
$item=new item;
$item->Item_Name=$request->get('iname');
$item->Item_Category=$request->get('icat');
$item->Price=$request->get('price');
$item->image_url=$request->get('img');
$item->Item_Type=$request->get('itype');
$item->save();
return redirect('/show');
}
Note: Where "Item_Name" is database table attribute name and "iname " is form field name
4) Make funtion to show database value into html table
public function disp()
{
$data= item::all();
{
return view('/Resturant Menu.add',['mir'=>$data]);
return redirect('/show');
}
}
Note:"mir" is key we can use as your wish and item is table name of database
4) Make Route
Route::POST('/Insert',[ItemController::class,'add']);
Route::get('/show',[ItemController::class,'disp']);
5) Use the key in table field to show the database table value into html table
@foreach ($item as $items)
<tbody>
<tr>
<th scope="row">{{$items['id']}}</th>
<td>{{$items['Item_Name']}}</td>
<td>{{$items['Item_Category']}}</td>
<td>{{$items['Price']}}</td>
<td>{{$items['img_url']}}</td>
<td>{{$items['Item_Type']}}</td>
<td>
</td>
</tr>
</tbody>
@endforeach
0 Comments