Support the ongoing development of Laravel.io →
Configuration Eloquent
Last updated 2 years ago.
0

maartenscholz said: This creates a SQL error (Table 'gks.types' doesn't exist) when migrating.

When migrating? No, this wouldn't cause an error when you're migrating. If you're trying to run

php artisan migrate

and you're getting an error that the table doesn't exist that means you're probably doing something wrong in the migration file that creates the table.

Last updated 2 years ago.
0

Sorry, I should have been more specific, if I do a migrate:reset and then migrate the error occurs. There is nothing wrong with my migration. If i remove

->where(['type' => implode('|',\Gks\Models\Type::getAllSlugs())]);

the migrate command works correct.

Laravel probably loads routes.php before migrating, and then throw an error because of trying to execute

\Gks\Models\Type::getAllSlugs()
Last updated 2 years ago.
0

What does the function getAllSlugs() do ? If it takes info from the db and before migrating you don't have any records, maybe that's the problem.

Last updated 2 years ago.
0

I forgot. I recently did something silimar. Just check for this in your routes.php

if (!App::runningInConsole()) {
    // code with model calls
}
Last updated 2 years ago.
0

Hi,

In my humble opinion, you shouldn't do it in the routes.php file.

  1. Add a "slug" field in your "types" database table

  2. In your ProjectController@index, start by creating a validation rule like:

public function index( $type ) {
   $rule = array ( 'type' => 'required|exists:types,slug');
   $validator = Validator::make( array('type'=>$type), $rule );
   if ( $validator->passes() ){
      // whatever
  }
  // keep going
}

Regards,

Jeremy

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.