I'm new to Laravel and I'm trying out a multiple-data insert into multiple tables according to this tutorial. I replicated the project but the data doesn't get through to the database when I insert with the forms. I can see the data when I manually insert through PhPMyAdmin, so I doubt it's a database connection problem. The values to be inserted get stuck like:
The OrderController is:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Orders;
use App\Items;
class OrderController extends Controller
{
public function index()
{
$orders=Orders::all();
return view('front_page.view',compact('orders'));
}
public function store(Request $request)
{
$data=$request->all();
$lastid=Orders::create($data)->id;
if(count($request->product_name) > 0)
{
foreach($request->product_name as $item=>$v){
$data2=array('orders_id'=>$lastid, 'product_name'=>$request->product_name[$item], 'brand'=>$request->brand[$item], 'quantity'=>$request->quantity[$item], 'budget'=>$request->budget[$item], 'amount'=>$request->amount[$item] );
Items::insert($data2);
}
}
return redirect()->back()->with('success','data insert successfully');
}
public function items($id)
{
$items=Items::where('orders_id','=',$id)->get();
return view('front_page.items',compact('items'));
}
}
The items.blade.php is:
@extends('layouts.master')
@section('title','view items')
@section('content')
<table class="table table-bordered">
<thead>
<tr>
<th>SL</th>
<th>Product Name</th>
<th>Brand</th>
<th>Quantity</th>
<th>Budget</th>
<th>Total Amount</th>
</tr>
</thead>
<tbody>
@foreach($items as $key=>$item)
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
@endforeach
</tbody>
</table>
@endsection
And the routes are:
Route::post('/orders','OrderController@store');
Route::get('/orders','OrderController@index');
Route::get('/items/{id}','OrderController@items');
What am I doing wrong? Or is it just a compatibility issue? Thanks
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Fm0lbS
via IFTTT
Aucun commentaire:
Enregistrer un commentaire