When I try to run php artisan migrate to migrate a missing migration to my database. I get the following exception:
[BadMethodCallException]
Call to undefined method Illuminate\Database\Query\Builder::up()
See down to get the complete log and stack trace.
I run the command on the console local on my own computer. But on my server it does not work either.
I have tried already the following:
1. composer update
2. artisan dump-autoload
3. Delete /vendor and do composer install
This (https://github.com/cartalyst/sentry/issues/257) has not helped because i don't have a compile.php file. (Cause on local development this is disabled by default from laravel.)
If you need more informations like the complete migration code. Please ask.
This is the complete stack trace from the log http://snippi.com/s/lz5z86f (I have put it into a snippet cause it is quite long.)
I had another class which had the same filename like the migration.
Cause of this the exception was thrown. Renaming and executeing artisan dump-autoload helped.
I had the same problem and then I realized that my migrations filename differed from the class name and that fixed the problem for me. Try that one.
Could you show us your migration since the Exception tells you that the method used for creating the tables etc. is not there. In every migration the layout should look something like this:
public function up() {
Schema::create('users', function($table)
{
$table->increments('id');
});
}
public function down() {
Schema::drop('users');
}
Maybe you are calling a Class instead of the ClassSeeder in your DatabaseSeeder or Seeder
Related
I happened to open two instances of Laragon at the same time. After that php artisan migrate started throwing strange errores like "Interface not found" when that interface is actually there and was correctly imported. Tried different migrations and also throws random errors. I even tried with an old (already migrated) migration, copy pasted the code and it also didn't work. Always related to classes/interfaces not being found.
I've just noted that a simple test:
<?php
use App\Book;
use Illuminate\Database\Migrations\Migration;
class BookTest extends Migration
{
public function up()
{
echo Book::HARDCOVER;
}
}
doesn't work; it says: 'Class 'App\Book' not found' . The book class is there and was imported from phpstorm with a simple click. So, php artisan isn't finding any of my project classes.
I've just confirmed that tinker can't find the classes either.
Ok, I've just noticed that if I change in the book class the namespace to '\App\Models\Store' (where the file actually is) and I do from tinker something like \App\Models\Store\Book::HARDCOVER, then it actually works. The thing I don't get is why it's now (suddenly) needing me to update the name space to work...
Don't know how but my composer version was 2 so I had to downgrade to 1.10 and all works again.
I am learning the Laravel by building a job portal app. And I am coding for the company side to edit their post.
Now I could go to url, ex) http://localhost:8000/jobs/23/edit. But on the screen shows me 404|not found error message
This is an screen shot
for edit page, I created views/jobs/edit.blade.php.
Of course, data is clearly inserted in my job table.
I tried to clear all the cache and, executed following commands.
1. composer dump-autoload
2. php artisan clear-compiled
3. php artisan optimize
4. php artisan config:cache
web.php
Route::get('/jobs/{id}/edit', 'JobController#edit')->name('job.edit');
JobController.php
public function edit($id)
{
$jobs = Job::findOrFail($id);
return view('jobs.myjob',compact('jobs'));
}
my-job.blade.php
I have an edit button and following code is a link it has.
{{route('job.edit',[$job->id])}}
My environment is Windows, XAMPP and local MySQL server.
try this way :
Edit Job {{$job->id}}
you can clear route cache by :
php artisan route:clear
update : run following command to clear cache
php artisan config:clear
php artisan cache:clear
I finally could solve this problem.
I changed to a new route.
Route::get('/test-jobs/{id}/edit', 'JobController#edit')->name('test-job.edit');
I created new blade.php like this, views/test-jobs/edit.blade.php
I also changed JobController.php
public function edit($id){
$jobs = Job::findOrFail($id);
return view('test-jobs.edit',compact('jobs'));
}
And finally, my-job.blade.php which has an edit button like this.
<button class="btn btn-dark">Edit</button>
But still, I don't know why it worked.
And also, I think I need another solution. Because in this way, I needed to create another new folder in views.
So if someone knows another solution, please let me know.
Thank you.
The problem is probably in the line return view('jobs.myjob',compact('jobs')); in your JobController.php, it returns the following view: resources/views/jobs/myjob.blade.php (which probably doesn't exist).
try changing the line return view('jobs.myjob',compact('jobs')); to return view('jobs.edit',compact('jobs'));, after the change it refers to resources/views/jobs/edit.blade.php and that should solve your problem.
there's defenitely something wrong with my Laravel.
I have the Laravel 5.4 installed. I have installed Composer on my windows globally. I have php artisan working, but I'm getting errors everywhere:
php artisan tinker
When I type in php artisan make:model Brand it says Model created succesfully.
Awesome, right? When I type in php artisan tinker and App/Brand::all() next, it says Class 'Brand' not found.
While I have Brand.php inside my app folder:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Brand extends Model
{
//
}
By the way, I'm following this series at laracast.
mySQL
I can't run the mysql command, though I have manually installed mySQL on my windows (globally as well).
It says
'mysql' is not recognized as an internal or external command,
operable program or batch file.
migrate
php artisan migrate gives me this error:
[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key
length is 767 bytes
Besides this php artisan migrate is working very well, it creates two tables for me: migrations and users. I thought that was because I have two files in my \database\migrations folder. But...
When I say php artisan make:migration create_brands_table --create=brands, it creates a file inside this folder indeed. Like it should. I add a few lines inside the up() function so it looks like this:
Schema::table('brands', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->text('description');
$table->timestamps();
});
But it does not create a table.
Please note that I did edit my .env file to make a proper database connection, otherwise php artisan migrate would not work on the other two tables I did create with the php artsian migrate command.
It only gives a alreadt exists error. I tried migrate:rollback and migrate:refresh as well. I tried doing this after the composer dump-autoload command, but it came with the same result.
I'm lost in the dark here, I am obviously new to Laravel, but some friends of mine who are familiar with Laravel have never experienced the problems I have.
I have tried to reinstall and create a new project and all... guess what: same results.
You got namespaces wrong, use backslash: App\Brand
To create a table use Schema::create and not Schema::table
The mysql part is not Laravel's concern and should not be in this question. Anyway you should check your environment PATH variable.
Regarding the already existing table issue, I ran into that before and here's what I've done, first delete your database file, in my case I was using sqlite so my file was database.sqlite, I deleted that and created a new one(don't delete it permanently just in case), run your migrations normally to be sure everything is working for the normal tables, also delete your old Brand migration, then when you are creating a new migration for your Brands table, lose the --create flag,
Just like this php artisan make:migration create_brands_table, at this point do as mentioned before and use the Schema::create instead of Schema::table, hopefully everything should be working fine now.
For implement of a Nested Set for my news category I want to use Baum package.
After installing this Package via Composer and add BaumServiceProvider to config/app.php providers, I try to install a new Model named Category via Below command:
php artisan baum:install MODEL
But I faced to the following error :
[InvalidArgumentException]
There are no commands defined in the "baum" namespace.
Of course I ran php artisan command and But there were no command named Baum on generated commands list.
What should I do?
First you have to add the code below in config/app.php:
Baum\Providers\BaumServiceProvider::class
If the problem still persists configuration files may be cached. Just call:
php artisan config:clear
Make sure that you added
Baum\Providers\BaumServiceProvider::class
To the providers array in the app.php file located in config/app.php
Whenever I know that I have added something into Laravel's core files, and it's not working from the command line, I typically just run
php artisan optimize
to regenerate all of the classes, and it will typically work. Running this command is something that I find myself doing fairly often.
In AppServiceProvider.php (app\Providers) you can modify register function: public function register()
{
$this->app->register(\Baum\Providers\BaumServiceProvider::class);
}
Not sure why 5.2 have error, just tweak a bit myself.
Try add this on APP/Console/kernel.php
protected $commands = [
//Commands\Inspire::class,
// Register Baum nestedset command
Commands\BaumCommand::class,
Commands\InstallCommand::class
];
and create two files and copy BaumCommand.php and InstallCommand in /vendor/baum/baum/src/Baum/console.
then change a namespace at the top.
namespace Baum\Commands;
to
namespace App\Console\Commands;
I'm working on a CMS and I have a little problem with my migrations. I added a new migration file and I wanted to add that one. That didn't work so I ran this bit:
php artisan migrate:reset
After that I ran this bit:
php artisan migrate:install
php artisan migrate
And now I get this error:
{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42S02]: Base table or
view not found:1146 Table 'cms.pages' doesn't exist (SQL: select * from `pages`)"
The error kinda tells me that it can't find the database, because that's true.
I also have a command that runs the migrate and I run that one like this:
php artisan app:install
But that shows the same error...
Remove any lines requesting data from your model from these files to be sure artisan is not trying to load data from your non-existent table:
bootstrap/start.php
app/start/global.php
app/start/local.php
app/routes.php
Also be sure to un-register any service providers that utilize data from that table in their register or boot methods inside of app/config/app.php.
The issue is that these files not only get executed for browser (web) requests, but for all requests, including command-line artisan invocations (e.g. php artisan migrate). So if you try to use something before it is available in any of these files, you are going to have a Bad Time.
You can use this to dictate when your app is running from the console.
I believe this issue only occurs when you run a command
if( !App::runningInConsole() ){
//allow laravel-menu to run
}
This way you will prevent data load from your non-existent table