Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.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从bdd返回错误数据_Php_Laravel_Laravel 5.7 - Fatal编程技术网

Php Laravel从bdd返回错误数据

Php Laravel从bdd返回错误数据,php,laravel,laravel-5.7,Php,Laravel,Laravel 5.7,我是拉拉维尔的乞丐,我按照一个教程创建了一个简单的积垢 经过一些操作,我得到了一个很好的结果,我看到了一些奇怪的东西。 当我使用::find方法按id获取数据时,返回的结果与数据库结果不完全相同 您可以看到,在第二个输入上缺少一个部件,在第三个输入上有一个额外的“/” somoene知道如何纠正这种行为吗 这是第一张图片中的index.blade.php页面 @extends('layout') @section('content') <style> .

我是拉拉维尔的乞丐,我按照一个教程创建了一个简单的积垢

经过一些操作,我得到了一个很好的结果,我看到了一些奇怪的东西。 当我使用::find方法按id获取数据时,返回的结果与数据库结果不完全相同

您可以看到,在第二个输入上缺少一个部件,在第三个输入上有一个额外的“/”

somoene知道如何纠正这种行为吗

这是第一张图片中的index.blade.php页面

@extends('layout')

@section('content')
    <style>
        .uper {
            margin-top: 40px;
        }
    </style>
    <div class="uper">
        @if(session()->get('success'))
            <div class="alert alert-success">
                {{ session()->get('success') }}
            </div><br />
        @endif
        <table class="table table-striped">
            <thead>
            <tr>
                <td>ID</td>
                <td> nom</td>
                <td> Price</td>
                <td> prenom</td>
                <td> adresse</td>
                <td> collectivite</td>
                <td> telephone</td>
                <td> mail</td>
                <td> ref</td>
                <td colspan="2">Action</td>
            </tr>
            </thead>
            <tbody>
            @foreach($clients as $client)
                <tr>
                    <td>{{$client->id_client}}</td>
                    <td>{{$client->nom_client}}</td>
                    <td>{{$client->prenom_client}}</td>
                    <td>{{$client->adresse_client}}</td>
                    <td>{{$client->nom_collectivite}}</td>
                    <td>{{$client->telephone_client}}</td>
                    <td>{{$client->mail_client}}</td>
                    <td>{{$client->ref_client}}</td>
                    <td><a href="{{ route('clients.edit',$client->id_client)}}" class="btn btn-primary">Edit</a></td>
                    <td>
                        <form action="{{ route('clients.destroy', $client->id_client)}}" method="post">
                            @csrf
                            @method('DELETE')
                            <button class="btn btn-danger" type="submit">Delete</button>
                        </form>
                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>
        <div>
@endsection
@extends('layout'))
@节(“内容”)
欧佩尔先生{
边缘顶端:40px;
}
@if(session()->get('success'))
{{session()->get('success')}

@恩迪夫 身份证件 笔名 价格 普雷诺姆 阿迪斯 集体化 电话 邮件 裁判 行动 @foreach($clients作为$client) {{$client->id_client} {{$client->nom_client} {{$client->prenom_client} {{$client->adresse_client} {{$client->nom_corporate} {{$client->telephone_client} {{$client->mail_client} {{$client->ref_client} @csrf @方法('DELETE') 删除 @endforeach @端部
下面是第二张图片中的edit.blade.php页面

@extends('layout')

@section('content')
    <style>
        .uper {
            margin-top: 40px;
        }
    </style>
    <div>sdsq</div>
    <div class="card uper">
        <div class="card-header">
            Edit client
        </div>
        <div class="card-body">
            @if ($errors->any())
                <div class="alert alert-danger">
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div><br />
            @endif
            <form method="post" action="{{ route('clients.update', $client->id_client) }}">
                @method('PATCH')
                @csrf
                <div class="form-group">
                    <label for="nom">nom client:</label>
                    <input type="text" class="form-control" name="nom_client" value={{$client->nom_client}} />
                </div>
                <div class="form-group">
                    <label for="prenom">prenom client:</label>
                    <input type="text" class="form-control" name="prenom_client" value={{$client->prenom_client}} />
                </div>
                <div class="form-group">
                    <label for="adresse">adresse client:</label>
                    <input type="text" class="form-control" name="adresse_client" value={{$client->adresse_client}}/>
                </div>
                <div class="form-group">
                    <label for="collectivite">collectivite client:</label>
                    <input type="text" class="form-control" name="nom_collectivite" value={{$client->nom_collectivite}} />
                </div>
                <div class="form-group">
                    <label for="telephone">telephone client:</label>
                    <input type="text" class="form-control" name="telephone_client" value={{$client->telephone_client}} />
                </div>
                <div class="form-group">
                    <label for="mail">mail client:</label>
                    <input type="text" class="form-control" name="mail_client" value={{$client->mail_client}} />
                </div>
                <div class="form-group">
                    <label for="ref">ref client:</label>
                    <input type="text" class="form-control" name="ref_client" value={{$client->ref_client}} />
                </div>
                <button type="submit" class="btn btn-primary">Update</button>
            </form>
        </div>
    </div>
@endsection
@extends('layout'))
@节(“内容”)
欧佩尔先生{
边缘顶端:40px;
}
sdsq
编辑客户端
@如果($errors->any())
    @foreach($errors->all()作为$error)
  • {{$error}}
  • @endforeach

@恩迪夫 @方法('补丁') @csrf nom客户端: nom_client}}/> prenom客户端: prenom_客户端}}/> ADRESE客户: 地址}}/> 集体客户: 名义集体主义}}/> 电话客户: 电话_客户}}/> 邮件客户端: mail_client}}/> 参考客户: ref_client}}/> 更新 @端部
这是我的ClientController.php控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\client;

class ClientController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $clients = client::all();

        return view('clients.index', compact('clients'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('clients.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'nom_client'=>'required',
            'prenom_client'=>'required',
            'adresse_client'=>'required',
            'nom_collectivite'=>'required',
            'telephone_client'=>'required',
            'mail_client'=>'required',
            'ref_client'=>'required'
        ]);
        $client = new client([
            'nom_client' => $request->get('nom_client'),
            'prenom_client'=> $request->get('prenom_client'),
            'adresse_client'=> $request->get('adresse_client'),
            'nom_collectivite' => $request->get('nom_collectivite'),
            'telephone_client'=> $request->get('telephone_client'),
            'mail_client'=> $request->get('mail_client'),
            'ref_client'=> $request->get('ref_client')
        ]);
        $client->save();
        return redirect('/clients')->with('success', 'Stock has been added');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id_client
     * @return \Illuminate\Http\Response
     */
    public function show($id_client)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id_client
     * @return \Illuminate\Http\Response
     */
    public function edit($id_client)
    {

        $client = client::find($id_client);

        return view('clients.edit', compact('client'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id_client
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id_client)
    {
        $request->validate([
            'nom_client'=>'required',
            'prenom_client'=>'required',
            'adresse_client'=>'required',
            'nom_collectivite'=>'required',
            'telephone_client'=>'required',
            'mail_client'=>'required',
            'ref_client'=>'required'
        ]);

        $client = client::find($id_client);
        $client->nom_client = $request->get('nom_client');
        $client->prenom_client = $request->get('prenom_client');
        $client->adresse_client = $request->get('adresse_client');
        $client->nom_collectivite = $request->get('nom_collectivite');
        $client->telephone_client = $request->get('telephone_client');
        $client->mail_client = $request->get('mail_client');
        $client->ref_client = $request->get('ref_client');
        $client->save();

        return redirect('/clients')->with('success', 'Stock has been updated');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id_client
     * @return \Illuminate\Http\Response
     */
    public function destroy($id_client)
    {
        $client = client::find($id_client);
        $client->delete();

        return redirect('/clients')->with('success', 'Stock has been deleted Successfully');
    }
}

您的代码将生成给定的html,因为您没有引用值:

<input type="text" class="form-control" name="adresse_client" value=s/>

您的代码将生成给定的html,因为您没有引用以下值:

<input type="text" class="form-control" name="adresse_client" value=s/>

还有一点我想补充的是,你们的餐桌顺序不正确

 <table class="table table-striped">
            <thead>
            <tr>
                <td>ID</td>
                <td> nom</td>
                <td> Price</td>
                <td> prenom</td>
                <td> adresse</td>
                <td> collectivite</td>
                <td> telephone</td>
                <td> mail</td>
                <td> ref</td>
                <td colspan="2">Action</td>
            </tr>
            </thead>
            <tbody>
            @foreach($clients as $client)
                <tr>
                    <td>{{$client->id_client}}</td> //ID
                    <td>{{$client->nom_client}}</td> //nom
                    //---------------------------------
                    // PRICE IS MISSING SO either remove from table or pass it from controller
                    //---------------------------------
                    <td>{{$client->prenom_client}}</td> // prenom
                    <td>{{$client->adresse_client}}</td> //adresse
                    <td>{{$client->nom_collectivite}}</td> //collectivite
                    <td>{{$client->telephone_client}}</td> //telephone
                    <td>{{$client->mail_client}}</td> // mail
                   // ............

身份证件
笔名
价格
普雷诺姆
阿迪斯
集体化
电话
邮件
裁判
行动
@foreach($clients作为$client)
{{$client->id\u client}}//id
{{$client->nom_client}}//nom
//---------------------------------
//缺少价格,请从表中删除或从控制器中传递
//---------------------------------
{{$client->prenom_client}//prenom
{{$client->adresse_client}}//adrese
{{$client->nom_groupite}//groupite
{{$client->telephone{u client}}//电话
{{$client->mail\u client}}//mail
// ............

在edit.blade.php中,请在@cbaconier提到的所有值中添加引号,我想添加的更多内容是,您的表顺序不正确

 <table class="table table-striped">
            <thead>
            <tr>
                <td>ID</td>
                <td> nom</td>
                <td> Price</td>
                <td> prenom</td>
                <td> adresse</td>
                <td> collectivite</td>
                <td> telephone</td>
                <td> mail</td>
                <td> ref</td>
                <td colspan="2">Action</td>
            </tr>
            </thead>
            <tbody>
            @foreach($clients as $client)
                <tr>
                    <td>{{$client->id_client}}</td> //ID
                    <td>{{$client->nom_client}}</td> //nom
                    //---------------------------------
                    // PRICE IS MISSING SO either remove from table or pass it from controller
                    //---------------------------------
                    <td>{{$client->prenom_client}}</td> // prenom
                    <td>{{$client->adresse_client}}</td> //adresse
                    <td>{{$client->nom_collectivite}}</td> //collectivite
                    <td>{{$client->telephone_client}}</td> //telephone
                    <td>{{$client->mail_client}}</td> // mail
                   // ............

身份证件
笔名
价格
普雷诺姆
阿迪斯
集体化
电话
邮件
裁判
行动
@foreach($clients作为$client)
{{$client->id\u client}}//id
{{$client->nom_client}}//nom
//---------------------------------
//缺少价格,请从表中删除或从控制器中传递
//---------------------------------
{{$client->prenom_client}//prenom
{{$client->adresse_client}}//adrese
{{$client->nom_groupite}//groupite
{{$client->telephone{u client}}//电话
{{$client->mail\u client}}//mail
// ............
在edit.blade.php中,请在@cbaconier提到的所有值中添加引号