Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.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
Javascript Can';无法从数据库中检索Id_Javascript_Php_Mysql_Laravel - Fatal编程技术网

Javascript Can';无法从数据库中检索Id

Javascript Can';无法从数据库中检索Id,javascript,php,mysql,laravel,Javascript,Php,Mysql,Laravel,尝试访问数据库时,无法从数据库中检索ID: 这是我的数据库: 这是我的事件控制器类: <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Event3; class EventsController extends Controller { /** * Display a listing of the resource. * * @return \

尝试访问数据库时,无法从数据库中检索ID:

这是我的数据库:

这是我的事件控制器类:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Event3;
class EventsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = Event3::get(['title','start','end','color']);

       return Response()->json($data);
    }

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

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
       $event = new Event3();
        $event->id = $request->id;
       $event->title = $request->title;
       $event->start = $request->date_start .' '. $request->time_start;
        $event->end = $request->date_end;
       $event->color = $request->color;
        $event->save();

        return redirect('/');
    }

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

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

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

你必须修改你的密码index@EventsController

public function index()
{
    $data = Event3::get(['id', 'title','start','end','color']);

   return Response()->json($data);
}
或者干脆打电话

Event3::all();

请注意,控制器中的store()方法用于创建新元素,id将自动填充。

您必须修改index@EventsController

public function index()
{
    $data = Event3::get(['id', 'title','start','end','color']);

   return Response()->json($data);
}
或者干脆打电话

Event3::all();

请注意,控制器中的store()方法用于创建新元素,id将自动填充。

发现错误,非常简单: 在控制器类中,忘记添加
id

 public function index()
    {
        $data = Event::get(['id', 'title', 'start', 'end', 'color']);
        return Response()->json($data);
    }

发现了错误,非常简单: 在控制器类中,忘记添加
id

 public function index()
    {
        $data = Event::get(['id', 'title', 'start', 'end', 'color']);
        return Response()->json($data);
    }

选中受保护的$fillable=[];在此处添加id store方法创建新元素时,id将自动填充您希望在此处实现什么?创建新元素或编辑现有元素?@OuailB至少创建新元素,它在phpmyadmin中说记录有一个id,但当我通过
https://social.com/events
,除了idcheck保护的$fillable=[]之外,我得到了所有东西;在此处添加id store方法创建新元素时,id将自动填充您希望在此处实现什么?创建新元素或编辑现有元素?@OuailB至少创建新元素,它在phpmyadmin中说记录有一个id,但当我通过
https://social.com/events
,我把所有东西都拿回来了,除了你回答之前我刚刚看到的,是的,我没有意识到的一个简单错误,你回答之前我刚刚看到的,是的,一个我没意识到的简单错误