Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

My page can't find my Model. Why?

I'm new to Laravel and I'm trying to figure this out.

I'm working through the tutorial at https://www.youtube.com/watch?v=v6SZerzfgIg.

My code right now looks like this:

Here's my "home.blade.php:"

<form action="/insert" method="Post">

Open in new window


My web.php page has my routes structured like this:

Route::get('/home', 'HomeController@index')->name('home');

Route::get('/display','InsertController@index');

Route::post('/insert', 'InsertController@add');

Open in new window


My InsertController looks like this:

use Illuminate\Http\Request;

class InsertController extends Controller
{
	
	public function display() {
		
	}
	
    public function add(Request $request) {
		
		add::display(Request::all());

	}
   
}

Open in new window


I'm thinking that "add::display(Request::all())" is targeting my "add" model sitting in my "app" directory. At that point, I've got this:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class add extends Model
{
    protected $fillable = ['question_text', 'keywords', 'required', 'type', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_e'];
}

Open in new window


I'm wrong, apparently. Because when I submit my form, I get this error:

Class 'App\Http\Controllers\add' not found

What am I doing wrong? And am I right in assuming that this code:

add::display(Request::all());

...is going to submit my data and then grab the "display" method and show that page?

I'm a mess...

Straighten me out, please...
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Why is Add extending model? Surely it should be extending Controllers?
Avatar of Bruce Gust

ASKER

Julian, I'm working through some tutorials which is why what I'm about to say may make you think I've got monkeys flying out of my nose.

My thought was that on line #12 of my InsertController.php...

add::display(Request::all());

..."add" was referring to my "add.php" Model. Some of this syntax is still fresh out of the box for me, so I'm not yet confident in the flow of things, but is that right and does that relate at all to what you're asking above?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Julian!

I have since been able to figure this out, but I do appreciate your weighing in. I'm going to wrap this question up just for the sake of database hygiene, but I've got another question brewing so feel free to check that out as well at https://www.experts-exchange.com/questions/29139247/Can-you-pass-variables-into-a-Class-in-PHP.html#questionAdd

Thanks!