Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 8中没有更改_Php_Mysql_Laravel - Fatal编程技术网

Php 我的布尔值在数据库Laravel 8中没有更改

Php 我的布尔值在数据库Laravel 8中没有更改,php,mysql,laravel,Php,Mysql,Laravel,我需要帮助。。我的布尔值未在数据库中更改。。我用的是拉威尔8 这是我在PostController.php中的代码 public function store(Request $request) { $request->validate([ 'post_title' => 'required|string|max:60', 'post_slug' => 'required|string|unique:posts,post_slug',

我需要帮助。。我的布尔值未在数据库中更改。。我用的是拉威尔8

这是我在PostController.php中的代码

public function store(Request $request)
{
    $request->validate([
        'post_title' => 'required|string|max:60',
        'post_slug' => 'required|string|unique:posts,post_slug',
        'post_thumbnail' => 'required',
        'post_excerpt' => 'required|string|max:500',
        'post_seq' => 'required',
        'post_description' => 'required|string',
        'post_meta_title' => 'required|string|max:60',
        'post_meta_description' => 'required|string|max:250',
        'post_meta_keyword' => 'required|string',
        'is_active' => 'required'
    ]);

    Post::create([
        'post_title' => $request->post_title,
        'post_slug' => $request->post_slug,
        'post_seq' => $request->post_seq,
        'post_thumbnail' => parse_url($request->post_thumbnail)['path'],
        'post_excerpt' => $request->post_excerpt,
        'post_description' => $request->post_description,
        'post_meta_title' => $request->post_meta_title,
        'post_meta_description' => $request->post_meta_description,
        'post_meta_keyword' => $request->post_meta_keyword,
        'is_active' => $request->has('is_active'),
        'user_id' => $request->user_id
    ]);
    Alert::success('Add Post', 'Added Post Success');
    // dd($request->all());
    return redirect()->route('posts.index');
}
下面是我在create.blade.php中的代码

<!-- status -->
   <div class="form-group{{ $errors->has('is_active') ? ' has-error' : '' }}">
        <label>Status</label>
        <select class="form-control" name="is_active" id="is_active">
             <option value="1" @if (old('is_active')==1) selected @endif>True</option>
             <option value="0" @if (old('is_active')==0) selected @endif>False</option>
        </select>
   </div>

地位
真的
假的
当我执行dd($request->all())时;它显示正确,当我选择时,is_活动字段改变,true=1 false=0


但在我的数据库中,is_活动布尔值仍然是0。。请帮助

您是否在
可填充
上添加了
是否处于活动状态
?在我的情况下,整数不起作用,但字符串工作正常,您可以尝试
'is\u active'=>($request->is\u active)?'1' : '0');是的,我确实保护了$fillable=['post_title','post_slug','post_缩略图','post_seq','post_摘录','post_描述','post_meta_title','post_meta描述','post_meta_关键字','处于活动状态'];我应该把这个放在哪里?”是否处于活动状态“=>($request->是否处于活动状态)?”1' : '0');将此行
'is_active'=>$request->has('is_active'),
更改为
'is_active'=>($request->is_active)?'1':“0'),