Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Work with laravel tinker

I'm new to laravel .

I want to work with php artisan tinker in cygwin but I am getting some errors in making an object. I watched some videos and the guy did this:

$article = new app\articles;

but when I do this it says:

PHP Fatal error:  Class 'app\articles' not found in eval()'d code on line 1

I tried this too:

$article = new c://xampp/htdocs/laravel/app/articles;

but it says this:

PHP Parse error: Syntax error, unexpected ':' on line 1
like image 917
amirhtk Avatar asked Aug 11 '15 16:08

amirhtk


People also ask

What is laravel Tinker used for?

Laravel Tinker allows you to interact with a database without creating the routes. Laravel tinker is used with a php artisan to create the objects or modify the data. The php artisan is a command-line interface that is available with a Laravel. Tinker is a command tool that works with a php artisan.

Why we use php artisan tinker?

Tinker is very convenient if you want to create test data in development – simply create two new test users with their factory. This command uses the model factory for users and creates two new users. Your output of this command should look similar to this – with different usernames and emails.

How do you dispatch jobs in Tinker?

To dispatch new jobs and test if the job is working, I run this code in Tinkerwell within the local application: $order = Order::latest()->first(); dispatch(new UploadOrderDataToMailchimp($order));


2 Answers

Tinker is case sensitive so if you are trying to create the object the way you are doing it it will fail so instead try placing the whole namespace in the exact way it is on your project

$article = new App\Article;

like image 134
Dimitri Acosta Avatar answered Oct 22 '22 16:10

Dimitri Acosta


Use terminal to go to your project, and type :

php artisan tinker

Then type the following command for example to create a new Article:

$article = new Article;

After that you can manipulate the article like any Article object :

$article->title = "foo";

Maybe you should take a look at Laravel Fundamentals at laracasts.com, it's a greate serie for Laravel beginners.

Regards.

like image 40
user3426711 Avatar answered Oct 22 '22 16:10

user3426711