Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bosstone's avatar

Laravel with Forge and Github

Hi, I am running my laravel app with Github and deploy it using forge. I need to add a new table into my app. Which steps do I have to do, to deploy the new table?

I have never done this before, so I do not know the necessary steps. In my mind, I have to

  • create a new Class "Reject"
  • create a new table "Rejects" with the fields (create_rejects_table.php)

in Atom, then push it using Github and deploy using forge. Am I right?

Thanks for your feedback and your advices,

Stefan

0 likes
4 replies
Nakov's avatar

@bosstone you are right for the steps, you also need to check if on Forge, in the Deploy Script, you have this line:

php artisan migrate --force

That will make sure that once your code is deployed, this acts as a post hook which will run your migration on the server.

aurawindsurfing's avatar

@nakov

You are right, however I would be very reluctant to put

php artisan migrate --force

in deployment script, It is better to ssh to your server and do it by hand and understand when and why you are doing it or even add column via GUI tool. It just feels safer to me. Some people might have $table->drop() in their migrations and it can create whole lot of issues.

Nakov's avatar

@aurawindsurfing good point, but then again. I've had this for 5 years now, never had such a bad experience.

  • Good code review
  • Staging release before Production

are couple of things that prevented me thus far to do something like that.

Don't agree that SSH and running php artisan migrate will prevent you from running wrong migration, but you can maybe forget to run the migration and experience errors in runtime, which is bad.

Using GUI works if you are the only person on the project, and you run the project only on one database, because again trying to remember that you need to add a column after you worked locally it is a lot more error prone. This is why we have migrations in Laravel. And writing a drop() call unintentionally is like trying to trick yourself :)

Bosstone's avatar

Hi, thank you very much for your support. I have this in my deploy script:

cd /home/forge/app.austrianweddingaward.at
git pull origin master
composer install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service php7.4-fpm reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    php artisan migrate --force
fi

This is my function


public function rejectProject(Request $data) {

        $id = $data->id;
        $project = Project::find($id);
        $project->stat = '3';
        $project->save();

        //get user email
        $project = Project::where('id', $id)->first();
        $user_id = $project->user_id;
        $user = User::where('id', $user_id)->first();

        //Add to table RejectingProject - this is what I have add to the function

        DB::table('rejects')->insert(
               array(
                      'user_id'     =>  $user_id,
                      'project_id'   =>  $id,
                      'projectname' => $project->name,
                      'text' => $data->emailBody
               )
          );

	//but it is not adding to the rejects table. I have also add app\Reject in the beginning of the script.

        // Send Email
        Mail::to($user->email)->send(new RejectingProject($data->emailBody, $project->name, $user->vorname.' '.$user->name));

        Session::flash('alert-success','Das Projekt wurde erfolgreich zurückgewiesen.');

        return response()->json(array('msg'=> 'Success'), 200);
    }

This is what I have add to the code, but it is not putting anything into the database. The idea is - instead of only sending Status E-Mail to the Customer, I will add the text of the E-Mail into a Table "Rejects" to show the text in the dashboard of the user:


//Add to table RejectingProject - this is what I have add to the function

        DB::table('rejects')->insert(
               array(
                      'user_id'     =>  $user_id,
                      'project_id'   =>  $id,
                      'projectname' => $project->name,
                      'text' => $data->emailBody
               )
          );

	//but it is not adding to the rejects table. I have also add app\Reject in the beginning of the script.

Thank you for your help!

Stefan

Please or to participate in this conversation.