0

I'm trying to retrieve data from a table called completion_date using Eloquent. My Model name is Completion and as per laravel documentation, i should declare a (protected) table name or else Eloquent will use 'completions' as the default table name. So i did this declaration. I'm getting problems with my Controller since i dont know which name to use to refer to my Model when i'm making the View. I'm getting an InvalidArgumentException that View [completion.lsz] not found. if i just use my model name to make the View.

Error:

InvalidArgumentException thrown with message "View [completion.lsz] not found."

Can someone pls help out?

Model

 <?php

 //Model (file name: Completion)

 class Completion extends Eloquent{
     protected $table = 'completion_date';
     public $timestamps = false;
 }

Controller

 class CompletionController extends BaseController  {

 public function index()    {
    $lsz = Completion::all();
    return View::make('completion.lsz', ['completion' => $lsz]);


   }    
 }

Route

 Route::get('/Completion', 'CompletionController@index');
6
  • What exactly do you mean by "refer to my table name when i'm making the View"? The table name normally has nothing to do with your view... Commented Nov 10, 2014 at 8:30
  • Fair enough. I'm simply following a tutorial here and very green. So how would you rewrite the return statement in the the index function in Controller so that i don't get the sql error 'Table not found'? Commented Nov 10, 2014 at 8:36
  • Honestly I don't know why you get a table not found. Could you update your question with the full Error message? Commented Nov 10, 2014 at 8:38
  • I have edited the question with some updates and the Error message. I recieved the sql error because the custom table name declaration was commented out. Commented Nov 10, 2014 at 8:52
  • Ahaa!! It can't find your VIEW file. Do you have app/views/completion/lsz.blade.php? If not, how does your views structure look like? Commented Nov 10, 2014 at 8:55

2 Answers 2

1

View names in Laravel work like a path. The . gets converted to a /
That means, your view resolves to the file app/views/completion/lsz.blade.php (or app/views/completion/lsz.php without Blade)

So you either have to change the name of your directory in the views folder to "completion" or change the view make command to:

View::make('lsz.lsz', ['completion' => $lsz]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks buddy. Error message is gone.
1

The error message says that the view file completion/lsz.blade.php was not found.

It's not related to the model or database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.