Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在laravel中获取URL值?_Php_Laravel - Fatal编程技术网

Php 如何在laravel中获取URL值?

Php 如何在laravel中获取URL值?,php,laravel,Php,Laravel,所以,我尝试了laravel,当我想获取URL值作为数据库的值时,我陷入了困境。这是我的控制器中的代码 public function store(Request $request, $shoe_id) { //Insert Data $cart = new Cart; $cart->user_id = Auth::user()->id; $cart->shoe_id = $shoe_id; $cart->quantity

所以,我尝试了laravel,当我想获取URL值作为数据库的值时,我陷入了困境。这是我的控制器中的代码

public function store(Request $request, $shoe_id)
{
    //Insert Data
    $cart = new Cart;
    
    $cart->user_id = Auth::user()->id;
    $cart->shoe_id = $shoe_id;
    $cart->quantity = $request->quan;

    $cart->save();

    return redirect()->back();
}
以下是我遇到的问题:

以下是我的网站的外观:

这是我的web.php:

Route::get('/','homeController@main')->name('home');
Route::get('/home','homeController@main')->name('home');
Route::get('/detail/{shoe_id}', 'homeController@detail');
Route::get('/cart/{shoe_id}','CartController@show');
Route::post('/cart/{shoe_id}','CartController@store');
这是我的刀:

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div style="text-align:center;">
                    <img src="{{ asset("$cart->shoe_image") }}" alt="" style=" width:350px; height:350px;">
                    <div class="card-header">{{$cart->shoe_name}}</div>
                    <div class="card-header">${{$cart->shoe_price}}</div>
                    <div class="card-header">{{$cart->shoe_description}}</div>
                </div>
                <div class="card-header form-group">
                    <form method="POST" action="/cart/{shoe_id}" enctype="multipart/form-data">
                        @csrf
                        <div class="form-row">
                            <div class="col-md-2">
                                <label for="quantity">Quantity:</label>
                            </div>
                            <div>
                                <input class = "form-control" type="text" id="quantity" name="quan"><br><br>
                            </div>
                            <button class="btn btn-primary" type="submit" name="addcart">Add to Cart</button>
                        </div>
                    </form>
                    
                    {{-- <a class="btn btn-primary" href="#">Add to Cart</a> --}}
                    
                </div>
                
            </div>
        </div>
    </div>
</div>
@endsection
@extends('layouts.app'))
@节(“内容”)
shoe_image“}}”alt=”“style=“宽度:350px;高度:350px;”>
{{$cart->shoe_name}
${{$cart->shoe_price}
{{$cart->shoe_description}
@csrf
数量:


添加到购物车 {{-- --}} @端部

我想做的是:把输入的数据输入数据库。我的数据库有一个名为cart的表,属性为id、user\u id、shoe\u id。

在表单操作中,您应该提供shoe\u id的实际值,然后它将按预期工作<代码>操作=“/cart/{{$cart->shoe_id}}”

@extends('layouts.app'))
@节(“内容”)
shoe_image“}}”alt=”“style=“宽度:350px;高度:350px;”>
{{$cart->shoe_name}
${{$cart->shoe_price}
{{$cart->shoe_description}
@csrf
数量:


添加到购物车 {{-- --}} @端部
在表单操作中,您应该提供鞋id的实际值,然后它将按预期工作<代码>操作=“/cart/{{$cart->shoe_id}}”

@extends('layouts.app'))
@节(“内容”)
shoe_image“}}”alt=”“style=“宽度:350px;高度:350px;”>
{{$cart->shoe_name}
${{$cart->shoe_price}
{{$cart->shoe_description}
@csrf
数量:


添加到购物车 {{-- --}} @端部
请向您展示路由实现,以及如何使用代码块中的表单和路由(web.php)文件中的路由声明调用urlPost您的刀片视图-请不要附加图像欢迎访问。。。
{shoe_id}
应该是什么?请向您展示路由实现,以及如何使用代码块中的routes(web.php)文件中的表单和路由声明调用urlPost您的刀片视图-请不要附加图像欢迎访问SO。。。
{shoe\u id}
应该是什么?
{$cart->shoe\u id}
将是
{{{$cart->shoe\u id}
@sta-Yep对不起我的错。谢谢你指出问题出在哪里。我的控制器呢?如何获得给定的{{$cart->shoe\u id}}在store方法中,
dd($shoe\u id)
的值是多少?它应该获得您从刀片视图传递的值作为路由参数这是值:“{shoe_id}”
{$cart->shoe_id}
{{$cart->shoe_id}
@sta Yep对不起,我的错了。谢谢你指出问题出在哪里。我的控制器呢?如何获得给定的{{$cart->shoe\u id}}在store方法中,
dd($shoe\u id)
的值是多少?它应该从blade视图中获取作为路由参数传递的值这是值:“{shoe_id}”