lundi 20 juin 2016

Laravel 5, can't insert via request method doest not exist

Hello that's what i'm trying to do without any success:

In welcome.blade I have a foreach with some boards and subboards(random generated by user) where you can click on subboard and go something like this /subboardOne. I got this on my routes.php

Route::get('/{subboaName}', 'ThreadController@index');
Route::post('/{subboaName}', 'ThreadController@store');

then you can post a thread on this subboard via form but since i really don't know how laravel knows where he is, the form is something like this:

<form class="form col-md-12 center-block" role="form" method="POST" action="/">

this $subboardcoll->id comes from the controller, where it sends via the index function the collection:

public function index($subboard)
{
    $subboardcoll = Subboard::where('subboaName', $subboard)->first();
    $threads = Thread::where('subboaId', $subboardcoll->id)
           ->orderBy('created_at', 'desc')
           ->get();
    return view('threads.thread', compact('threads', 'subboardcoll'));
}

then i'm trying to send my form and store the thread autoinserting the subboardId but laravel doesn't recognize subboards method:

public function store(Request $request)
    {
        $this->validate($request, [
            'comentario' => 'required|max:2000',
            //'g-recaptcha-response' => 'required|recaptcha',
            //'imagen' => 'required',
        ]);

        $request->subboards()->threads()->create([
            'thrName' => $request->nombre,
            'thrComment' => $request->comentario,
            'thrImg' => $request->imagen,
            'thrSubject' => $request->tema,
        ]);

        return redirect()->back();

    }

And gives me this erorr:

BadMethodCallException in Macroable.php line 81: Method subboards does not exist.

Can you guys helpme to know why? also is there better form to do what i'm trying? im newbie on laravel, thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire