2

I am trying to create an API Resource in Laravel 5.4 and also 5.6 and by some reason when I create type the make:resource command, it says cannot be found. Any assistance will be greatly appreciated. And the make:factory as well cannot be found

this is the command i run

Felix@DESKTOP-O26O7PO MINGW64 /c/wamp/www/larticles $ php artisan make:resource exampleresource

Command make:resource is not defined.

5
  • You have told us nothing with your post. You need to provide code samples and specific outputs of errors. Commented Aug 2, 2018 at 11:42
  • Its an error on the CLI which says Command "make:resource" is not defined. Commented Aug 2, 2018 at 11:56
  • Perform a php artisan list, which will prompt all the available artisan commands. Tell us (preferably written in your topic to inform folks) what you have around make commands. Commented Aug 2, 2018 at 12:11
  • php artisan list gives me all the list of commands excluding the ones I stated in my question. Commented Aug 2, 2018 at 15:49
  • What I did was to upgrade to laravel 5.5 and php to version 7.1.16 because laravel >= 5.5 requires php >=7 to run and after that, I run composer update to update my settings and it worked perfectly after running php artisan list. I can now run the make:resource and make:factory. Commented Aug 7, 2018 at 12:34

5 Answers 5

1

Seems that make:resource is not available in 5.4, also when changing laravel to new version, you should use composer update after changing the specified version to update your autoload scripts.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah I actually upgraded to laravel 5.5 and php to version 7.1.16 because laravel >= 5.5 requires php >=7 to run and after that, I run composer update to update my settings and it worked perfectly after running php artisan list. I can now run the make:resource and make:factory.
1

on Laravel 5.2> version we use factory in ModelFactory file for example

/** @var \Illuminate\Database\Eloquent\Factory $factory */

$factory->define(App\Article::class, function (Faker\Generator $faker) {

static $password; //this is default created

return [ 'name' => $faker->name, 'email' => $faker->unique()->safeEmail, 'password' => $password ?: $password = bcrypt('secret'), 'remember_token' => str_random(10), ];

});

the second creatin in below

/** @var \Illuminate\Database\Eloquent\Factory $factory */

$factory->define(App\Model::class, function (Faker\Generator $faker) {

return [ 'title' => $faker->text(50), 'body' => $faker->text(250) ];

});

Comments

0

I had tried to run php artisan make:factory ArticleFactory but it didn't work.

This is everything I had to do to resolve it:

update php to 7+

0) Run php --version on CLI to determine what version your composer is running. If it's not 7+, then do following:

1) Uninstall composer

2) Install composer → select the path environment variable of 7+

update laravel to 5.5+

1) Run php artisan --version to see which version you are on. Mine was at 5.4

2) Go to composer.json and edit the "laravel/framework" to "5.5.*"


Rerun command. Should work now

this is on a windows 10 PC so your results may vary.

Comments

0

I was having the same issue

turns out I was using an older version of laravel 2.x

# reinstall `laravel` using `composer`

composer global remove laravel/installer
composer global require "laravel/installer:^4.0"

this didn't work for me, because I had php 5.5 and laravel 4.0 requires php 7.x

# update `php` using `brew`  
brew upgrade php
# or
brew install [email protected]

didn't work for me, because i was using an older unsupported mac osx 10.11

# download `php` with third-party support
curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1

# add `php` to path 
echo 'export PATH="/usr/local/php5/bin:${PATH}"' >> .bash_profile
# reinstall composer

rm /usr/local/bin/composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '756890a4488ce9024fc62c56153228907f1545c228516cbf63f885e036d37e9a59d27d63f46af1d4d07ee0f76181c7d3') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

mv composer.phar /usr/local/bin/composer
# reinstall `laravel` with `composer`

composer global remove laravel/installer
composer global require "laravel/installer:^4.0" --ignore-platform-reqs

refrences

How to Uninstall Laravel?
Package laravel/ui at version has a PHP requirement incompatible with your PHP version (5.6.40)
Install PHP 7.3 for Mac WITHOUT HomeBrew
Remove composer

Comments

-1

What I did was to upgrade to laravel 5.5 and php to version 7.1.16 because laravel >= 5.5 requires php >=7 to run and after that, I run composer update to update my settings and it worked perfectly after running php artisan list. I can now run the make:resource and make:factory. Thanks for the contributions.

3 Comments

hi, it would be really helpful if you would add more details to how you did this?
Are you having the same issue?
yeah, but i found a solution. i've also it documented above

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.