Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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 为什么可以';t laravel检测我的“;“公众”;复选框,是否使用验证?_Php_Laravel_Validation - Fatal编程技术网

Php 为什么可以';t laravel检测我的“;“公众”;复选框,是否使用验证?

Php 为什么可以';t laravel检测我的“;“公众”;复选框,是否使用验证?,php,laravel,validation,Php,Laravel,Validation,我的laravel项目有问题,我无法找出我做错了什么 我的项目有以下相关文件: <?php <?php namespace App\Http\Controllers\Admin; use App\Models\User; use Illuminate\Support\Facades\Hash; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class UserController exten

我的laravel项目有问题,我无法找出我做错了什么

我的项目有以下相关文件:

<?php

<?php

namespace App\Http\Controllers\Admin;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function list()
    {

        $users = User::all();

        return view('admin.users.list')->with('users',$users);

    }
    // here we create fuction for edit users
    public function updateUserView(Request $request, $id)
    {
        $user = User::findOrFail($id);
        return view('admin.users.edit')->with('user',$user);
    }

    // here we create function for update button
    public function updateUserPut(Request $request, $id)
    {

        $validated = $request->validate([
            'name' => 'required|max:30',
            'email' => 'required|email',
            'public' => 'boolean',
            'phoneNumber' => '',
            'usertype' => '',
            'password' => 'required|confirmed|min:8|max:255',
        ]);

        $users = User::find($id);
        $users->name = $validated['name'];
        $users->email = $validated['email'];
        $users->public = $validated['public'];
        $users->phoneNumber = $validated['phoneNumber'];
        $users->usertype = $validated['usertype'];
        $users->password = Hash::make($validated['password']);
        $users->update();

        return redirect('/admin/users')->with('status','User is updated');
    }

public function createUserView()
{
    return view('admin.users.create');
}

    public function createUserPost(Request $request)
    {

        $validated = $request->validate([
            'name' => 'required|max:30',
            'email' => 'required|email|unique:users',
            'public' => 'boolean',
            'phoneNumber' => '',
            'usertype' => '',
            'password' => 'required|confirmed|min:8|max:255',
        ]);

        User::create([
        'name' => $validated['name'],
        'email' => $validated['email'],
        'public' => $validated['public'],
        'phoneNumber' => $validated['phoneNumber'],
        'usertype' => $validated['usertype'],
        'password' => Hash::make($validated['password'])
        ]);

        return redirect('/admin/users')->with('status','User is created');
    }

    //delete function
    public function deleteUser($id)
    {
        $users = User::findOrFail($id);
        $users->delete();

        return redirect('/admin/users')->with('status','User deleted');

    }
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->boolean('public')->default(0);
            $table->string('phoneNumber')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('usertype')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

            //Hier komt de aanvullende informatie die op de profielpagina wordt getoond
            $table->string('workExperience')->nullable(); //de werkervaring van de betreffende gebruiker
            $table->string('smallBiography')->nullable(); //beschrijving over hoe de betreffende gebruiker is begonnen met zijn werk.
            $table->string('motivation')->nullable(); //beschrijving over wat de betreffende gebruiker motiveert, om zijn werk te doen.
            $table->string('interests')->nullable(); //beschrijving waarom gebruiker het vak hem zo intresseert.
            $table->string('hobbies')->nullable(); //hobbies van gebruiker
            $table->string('function')->nullable(); //Functietitel van gebruiker

            //Profile social links
            $table->string('website')->nullable(); //website van gebruiker
            $table->string('twitter')->nullable(); //website van gebruiker
            $table->string('instagram')->nullable(); //website van gebruiker
            $table->string('facebook')->nullable(); //website van gebruiker
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

@extends('layouts.master')

@section('title')
            Edit User:
@endsection()

@section('content')

<div class="container">
    <div class="row">
        <div class="col-md-12"><!-- 12 row -->
            <div class="card">
                <div class="card-header">
                    <h3>Edit User</h3>

                    @if ($errors->any())
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-8"> <!--col-md-8 means 8 row  and form put into one row and updtate the button below-->
                            <form action="/admin/user/edit/{{ $user->id }}" method="POST" ><!-- here we update the button-->
                                {{ csrf_field() }}
                                {{ method_field('PUT') }}
                        <div class="form-group">
                            <label>Name</label>
                            <input type="text" name="name" value="{{ $user->name }}" class="form-control">
                        </div>

                        <div class="form-group">
                            <label>E-mail</label>
                            <input type="text" name="email" value="{{ $user->email }}" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Public</label>
                            <input type="checkbox" name="public" value="{{ $user->public }}" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Phone number</label>
                            <input type="text" name="phoneNumber" value="{{ $user->phoneNumber }}" class="form-control">
                        </div>

                        <div class="form-group">
                            <label>Give Role</label>
                            <select name="usertype" class="form-control">
                                <option value="admin">Admin</option>
                                <option value="vendor">Vendor</option>
                                <option value="">None</option>
                            </select>
                        </div>

                         <div class="form-group">
                            <label>Password</label>
                            <input type="password" name="password" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Confirm password</label>
                            <input type="password" name="password_confirmation" class="form-control">
                        </div>

                        <button type="submit" class="btn btn-success">Submit</button>
                        <a href="/admin/users" class="btn btn-danger">Cancel</a>
                    </form>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</div>

@endsection()

@section('scripts')


@endsection()
控制器(UserController.php):

<?php

<?php

namespace App\Http\Controllers\Admin;

use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    public function list()
    {

        $users = User::all();

        return view('admin.users.list')->with('users',$users);

    }
    // here we create fuction for edit users
    public function updateUserView(Request $request, $id)
    {
        $user = User::findOrFail($id);
        return view('admin.users.edit')->with('user',$user);
    }

    // here we create function for update button
    public function updateUserPut(Request $request, $id)
    {

        $validated = $request->validate([
            'name' => 'required|max:30',
            'email' => 'required|email',
            'public' => 'boolean',
            'phoneNumber' => '',
            'usertype' => '',
            'password' => 'required|confirmed|min:8|max:255',
        ]);

        $users = User::find($id);
        $users->name = $validated['name'];
        $users->email = $validated['email'];
        $users->public = $validated['public'];
        $users->phoneNumber = $validated['phoneNumber'];
        $users->usertype = $validated['usertype'];
        $users->password = Hash::make($validated['password']);
        $users->update();

        return redirect('/admin/users')->with('status','User is updated');
    }

public function createUserView()
{
    return view('admin.users.create');
}

    public function createUserPost(Request $request)
    {

        $validated = $request->validate([
            'name' => 'required|max:30',
            'email' => 'required|email|unique:users',
            'public' => 'boolean',
            'phoneNumber' => '',
            'usertype' => '',
            'password' => 'required|confirmed|min:8|max:255',
        ]);

        User::create([
        'name' => $validated['name'],
        'email' => $validated['email'],
        'public' => $validated['public'],
        'phoneNumber' => $validated['phoneNumber'],
        'usertype' => $validated['usertype'],
        'password' => Hash::make($validated['password'])
        ]);

        return redirect('/admin/users')->with('status','User is created');
    }

    //delete function
    public function deleteUser($id)
    {
        $users = User::findOrFail($id);
        $users->delete();

        return redirect('/admin/users')->with('status','User deleted');

    }
}

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email')->unique();
            $table->boolean('public')->default(0);
            $table->string('phoneNumber')->nullable();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('usertype')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

            //Hier komt de aanvullende informatie die op de profielpagina wordt getoond
            $table->string('workExperience')->nullable(); //de werkervaring van de betreffende gebruiker
            $table->string('smallBiography')->nullable(); //beschrijving over hoe de betreffende gebruiker is begonnen met zijn werk.
            $table->string('motivation')->nullable(); //beschrijving over wat de betreffende gebruiker motiveert, om zijn werk te doen.
            $table->string('interests')->nullable(); //beschrijving waarom gebruiker het vak hem zo intresseert.
            $table->string('hobbies')->nullable(); //hobbies van gebruiker
            $table->string('function')->nullable(); //Functietitel van gebruiker

            //Profile social links
            $table->string('website')->nullable(); //website van gebruiker
            $table->string('twitter')->nullable(); //website van gebruiker
            $table->string('instagram')->nullable(); //website van gebruiker
            $table->string('facebook')->nullable(); //website van gebruiker
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

@extends('layouts.master')

@section('title')
            Edit User:
@endsection()

@section('content')

<div class="container">
    <div class="row">
        <div class="col-md-12"><!-- 12 row -->
            <div class="card">
                <div class="card-header">
                    <h3>Edit User</h3>

                    @if ($errors->any())
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-8"> <!--col-md-8 means 8 row  and form put into one row and updtate the button below-->
                            <form action="/admin/user/edit/{{ $user->id }}" method="POST" ><!-- here we update the button-->
                                {{ csrf_field() }}
                                {{ method_field('PUT') }}
                        <div class="form-group">
                            <label>Name</label>
                            <input type="text" name="name" value="{{ $user->name }}" class="form-control">
                        </div>

                        <div class="form-group">
                            <label>E-mail</label>
                            <input type="text" name="email" value="{{ $user->email }}" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Public</label>
                            <input type="checkbox" name="public" value="{{ $user->public }}" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Phone number</label>
                            <input type="text" name="phoneNumber" value="{{ $user->phoneNumber }}" class="form-control">
                        </div>

                        <div class="form-group">
                            <label>Give Role</label>
                            <select name="usertype" class="form-control">
                                <option value="admin">Admin</option>
                                <option value="vendor">Vendor</option>
                                <option value="">None</option>
                            </select>
                        </div>

                         <div class="form-group">
                            <label>Password</label>
                            <input type="password" name="password" class="form-control">
                        </div>

                         <div class="form-group">
                            <label>Confirm password</label>
                            <input type="password" name="password_confirmation" class="form-control">
                        </div>

                        <button type="submit" class="btn btn-success">Submit</button>
                        <a href="/admin/users" class="btn btn-danger">Cancel</a>
                    </form>
                        </div>
                    </div>

                </div>

            </div>
        </div>
    </div>
</div>

@endsection()

@section('scripts')


@endsection()
当我单击edit.blade.php文件上的提交按钮时,它表示“public”索引未定义。 我仔细检查了复选框名称和验证,但一切看起来都很好

有人知道为什么控制器没有正确接收“public”复选框数据吗

谢谢你的帮助

问候


Dave

为客户展示路线that@JohnLobo我只是把它添加到上面的解释中。感谢您的帮助try'public'=>'boolean',t'public'=>'required | boolean',这是否回答了您的问题@JohnLobo我刚刚试过,现在需要我在继续之前勾选public复选框。并且公共复选框数据未保存到数据库中