Hopefully this example can guide you:
app\MyModels\Painting.php
<?php namespace App\MyModels;
use Illuminate\Database\Eloquent\Model;
class Painting extends Model {
protected $connection = 'mysql';
protected $primaryKey = 'id';
protected $table = 'painting';
protected $fillable = array(
'name',
'artist',
'price'
);
public $timestamps = false;
}
app\Http\Controllers\MyController.php
<?php namespace App\Http\Controllers;
use App\MyModels\Painting;
class MyController extends Controller {
public function index()
{
$art = new Painting;
$art->name = 'Mona Lisa';
$art->artist = 'Leonardo de Vinci';
$art->price = 300000000;
$art->save();
}
}
Make sure your mysql is setup with correct credentials in app\config\database.php and a painting table exists.
This should get you started.
This worked really very well. I just started laravel and wanted to store data in db without going through a lot of reading.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community