mercredi 26 octobre 2016

Laravel not inserting Auth::id into table

I'm looking to insert multiple column values into a table 'answers'. I'm inserting a question_id from questions table, which is being inserted successfully.

But it's not inserting the auth:user() id now, returning '0' in the table

answercontroller code:

<?php

namespace App\Http\Controllers;

use App\questions;
use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;

class answerController extends Controller
{
    public function store($question_id,Requests\answerAddRequest $request)
    {
        Auth::user()->questions()->findOrFail($question_id)->first()->answers()->create($request->all());
    }
}

If I remove the questions()->findOrFail($question_id)->first() part, it inserts the auth::id, but not with this, how can I fix it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire