How to get record using the command line in Laravel
In this tutorial How to get records using the command line in Laravel. Laravel default provides tinker.
Tinker is a command tool that works with a PHP artisan base. Tinker mostly use without creating the routes. tinker is used to create objects or modify the data.
Open terminal and write this command.
$ php artisan tinker

Get record
DB::table('demo')->get();
Output:
=> Illuminate\Support\Collection {#3136
all: [
{#3140
+"id": 1,
+"first_name": "Joi",
+"last_name": "Die",
+"created_at": "2020-02-04 22:57:30",
+"updated_at": "2020-02-15 02:49:50",
},
{#3132
+"id": 2,
+"first_name": "Joi",
+"last_name": "Die",
+"created_at": "2020-02-04 22:57:55",
+"updated_at": "2020-02-15 02:49:42",
},
...
],
}
>>>
== OR ==
Demo::get();
Output:
[!] Aliasing 'Demo' to 'App\Demo' for this Tinker session.
=> Illuminate\Database\Eloquent\Collection {#3148
all: [
App\Demo {#3149
id: 1,
first_name: "Joi",
last_name: "Die",
created_at: "2020-02-04 22:57:30",
updated_at: "2020-02-15 02:49:50",
},
App\Demo {#3150
id: 2,
first_name: "Joi",
last_name: "Die",
created_at: "2020-02-04 22:57:55",
updated_at: "2020-02-15 02:49:42",
},
...
],
}
>>>
Here Demo is a model name.
Close tinker
>>> Exit Output : Exit: Goodbye