Latest

Thursday, July 6, 2017

Can't retrieve Id from the database

Asked by: Rachel


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'

    ];
}


Source

No comments:

Post a Comment

Adbox