Я более ловкий человек, поэтому я не очень хорошо справляюсь с jquery.У меня есть проект, который я перенял у кого-то, и я должен выполнить запрос get на свой контроллер и добавить возвращенные данные для просмотра.Я знаю, что это расплывчато, но я был бы признателен за любую помощь.
<tbody>
@foreach($restaurant_meals as $meal)
<tr>
<td>
{{$meal->name}}
</td>
<td>
${{$meal->price}}
</td>
<td>
<a href=""><i class="fa fa-plus-circle"></i></a>
</td>
</tr>
@endforeach
</tbody>
Это мой взгляд.Это мой запрос AJAX.
<script type="text/javascript">
$(documnent).ready(function(){
$.ajax({
method: 'GET', // Type of response and matches what we said in the route
url: '/addtocartid' + id, // This is the url we gave in the route
data: {'id' : id}, // a JSON object to send back
success: function(response){ // What to do if we succeed
console.log(response);
}
});
});
Тогда мой контроллер будет
public function getaddtoCart(Request $request, $id)
{
$product = Product::find($id);
$oldCart = Session::has('cart') ? Session::get('cart') : null;
$cart = new Cart($oldCart);
$cart->add($product, $product->id);
$request->session()->put('cart', $cart);
return redirect()->route('home');
}
Любая помощь будет оценена