Ludwig Supraphonic Ludwig Supraphonic - 1 year ago 133
JSON Question

Json Laravel Model

How to write model in Laravel without creating Database and with function getData that returns Json? Something like:


namespace App;

use Illuminate\Database\Eloquent\Model;

class Table extends Model
protected $table = 'table';
protected $fillable = [

But without database.

I would be grateful for help

Answer Source

You need to extend Model only if you're using Eloquent.

If you just need to get json data from somewhere, create usual class which gets data from somewhere and returns JSON:

class MyModel
    public function getJsonData()
        $jsonData = // get json data from somewhere

        return $jsonData;

Register this class in composer.json file, run composer dumpauto and use your class:

$model = new MyModel();
$data = $model->getJsonData();