dousuohe5882 2017-07-06 21:18
浏览 52
已采纳

无法从数据库中检索Id

I can't retrieve the ID from my database when I try to access it :

enter image description here

This is my database: enter image description here

This is my event controller class:

<?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)
    {
        //
    }
}

I have tried adding the following:

$event->id= $request->id; into the above class but that didn't help .

Event3

namespace App;

use Illuminate\Database\Eloquent\Model;

class Event3 extends Model
{
    /**
     * @var string
     * [$table description]
     * @var string
     */

    protected $table = 'event3s';

    public $timestamps = false;

    /**
     * @var string
     * [$table description]
     * @var string
     */
    protected $filltable =[
        'title','start','end','color'

    ];
}
  • 写回答

2条回答 默认 最新

  • douzhangjian1505 2017-07-06 21:42
    关注

    You have to modify your index@EventsController

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

    or simply call

    Event3::all();
    

    Note that the store() method in your controller is for creating a new element, the id will be filled automatically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试