My page can't find my Model. Why?

Bruce Gust
Bruce Gust used Ask the Experts™
on
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...
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Why is Add extending model? Surely it should be extending Controllers?
Bruce GustPHP Developer

Author

Commented:
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!
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Sorry Bruce - you are correct - I was doing a speed view of the video and missed that you were building the model.

Can you show us more of the code so we can try and replicate.
Bruce GustPHP Developer

Author

Commented:
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!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial