I am relatively new to Laravel 5.1 and version control with Laravel. I created an Eloquent model named Article. I have a route that goes to the articles controller with the proper reference to a class. But in the Controller I referenced back to the article controller to get a JSON list of all entries in the articles in the database.
So here is the error I got:
PDOException in Connector.php line 50:
could not find driver
in Connector.php line 50
at PDO->__construct('mysql:host=localhost;dbname=mantella', 'root', 'root', array('0', '2', '0', false, false)) in Connector.php line 50
So initially I thought I might have set the driver wrong or input the incorrect database login. I set up the database information in the.env file. But all of the information in the .env file was correct.
Any way here is my Article Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $fillable = [
'title',
'body',
'published_at'
];
}
And here is the controller:
<?php
namespace App\Http\Controllers;
use App\Article;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class ArticlesController extends Controller
{
public function index()
{
$articles = Article::all();
return $articles;
}
}
Just to be safe here is the route:
<?php
Route::get('articles', 'ArticlesController@index');
I went into php artisan for laravel and used tinker. I typed $article = App\Article::get(); and that displayed all of the information in the database. I could have easily missed something. Can someone help me figure out why it isn't working in the controller and why it worked in tinker?