Support the ongoing development of Laravel.io →
Cache Database Eloquent
Last updated 1 year ago.
0

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.

Last updated 9 years ago.
0

This worked really very well. I just started laravel and wanted to store data in db without going through a lot of reading.

0

Thank you)))

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.