Laravel Multi tenancy - php

In my laravel project I am using multi tenancy. For project related work I am creating a laravel custom artisan command. I am trying to connect with repository model in that artisan command that I am creating. But I could not connect with the database. It says
Database [tenant] not configured.
How to use multi tenancy in my custom artisan command. So that I can use all the needed repository models in custom artisan command. Please suggest.

I assume you are using: hyn/multi-tenant
To run specific commands you could use the tenancy:run command. Lets say you have a command sync:donuts, which needs to be run on tenant id=1.
Then you should use:
php artisan tenancy:run sync:donuts --tenant=1
Read more in the documentation

Related

laravel command php artisan make:model run all commands in Commands folder

Why php artisan run all commands in the folder Commands when I create a model for example ?
Did I made something wrong ?
Laravel will initialize all the commands (User defined and Default commands) whenever you run any command in laravel application.
Which means don't perform any operation in __construct method of the commands.
For Example:
If you are performing any Databse operation in __construct method of custom command it will perform Databse operation no matter what command to ran.
So Move all the logics and operations to handle method of command.
I have faced the same issue back in the day You can see the github issue to clarify.
Artisan is the command line interface included with Laravel. Artisan exists at the root of your application as the artisan script and provides a number of helpful commands that can assist you while you build your application.
See more at : https://laravel.com/docs/8.x/artisan

Run php artisan command in out of laravel project

I am writing an installer for laravel project.
but for some reason, I don't run this installer from laravel project.
I use PHP code. I want to use php artisan migrate on my installer and I know that I can use this command system("php artisan migrate") but I don't want to use system functions on my installer. Is there any way to artisan command on PHP out of laravel?
Unfortunately artisan is baked into the Laravel Framework so your options are limited but you still have options.
Use the Spatie laravel-migrate-fresh package (be sure to read before use)
This would be suitable for a fresh install process
Use a shell script for your build
You can easily incorporate a shell script to run your migrations
Roll your own installer using Symfony's console
Vivek Kumar Bansal provides a good article on his Blog to do just this
Create a standalone installer using Laravel
This can contain your migrations and other commands (with input if you like)
Nuno Maduros Laravel Zero could actually be perfect for you!
It has migrations built in
You can use php's exec() function.
http://php.net/manual/en/function.exec.php
exec('php artisan migrate');

How to setup mysql database in laravel

I am new laravel programmer, and I have simple question
about setting up database.
Assume that I create all required migrations, models, and eloquent relationships, also configure mysql database in laravel, now in this point, is laravel will create all mysql tables required in server's DB according to migrations, models, and eloquent that I created before?
In other words, do I need to create tables in mysql server as scratch developer do?
To create a migration, use the make:migration Artisan command:
php artisan make:migration create_users_table
To run all of your outstanding migrations, execute the migrate Artisan command:
php artisan migrate
Laravel have many commands from console.
from console,go to your project folder path run php artisan list to see all avaliable commands.
your question asked how to create tables after you created migrations, which is php artisan migrate.

Using Illuminate Database outside Laravel without PHP Artisan Commands

I'm trying to set up database migrations using Illuminate's Database outside of a Laravel 4.2 project. Everything I'm reading online indicated that it is completely doable to use any Illuminate components outside of Laravel, but the difficulty I'm having is creating the database migrations without using Artisan commands ("php artisan make:migration create_user_table"). If any one could help me out with this, I'd really appreciate it, because I know someone has had to find a solution to the problem before.
Thanks!
If you want to use artisan commands you should include the package of it and configure your application accordingly.
illuminate\database package doesn't provide you and artisan commands to use.

Laravel - php artisan make:model Project Doesnt Work

I need to use this command to create a Model.
And when I do that:
php artisan make:model Project
I recieve
[InvalidArgumentException]
There are no commands defined in the "make" namespace.
So, in the tutorial that i'm following the guy uses this to make a model.
What Should I Do?
So, I discover i'm using laravel 4 and this command doenst exist there.
How Can I build a Model without this make command?
The make:model command is new to Laravel 5 so won't be available to you in 4.
To make a model you can simply create a new file in your models folder with the following code
class MyModel extends \Illuminate\Database\Eloquent\Model {
// Code here
}
There is a package available from Jeffrey Way (who created Laracasts) that has some commands that will generate many things for you, including models, which I found really useful when developing with 4. https://github.com/JeffreyWay/Laravel-4-Generators
To generate Models with artisan in laravel 4 you need install JeffreyWay way's package.
It has amazing generators for your laravel 4 app

Categories