Avatar of Bruce Gust
Bruce Gust
Flag 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...
LaravelPHP

Avatar of undefined
Last Comment
Bruce Gust

8/22/2022 - Mon
Julian Hansen

Why is Add extending model? Surely it should be extending Controllers?
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
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bruce Gust

ASKER
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!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck