Laravel Artisan Console
1 min readMar 4, 2020
Laravel ile kendi artisan komut dosyanızı oluşturun. Hızlı ve cronjob için kısa komutlar belirleyin.
php artisan list# Tüm Komutları Görüntüler
Yeni bir komut oluşturmak için aşağıdaki adımları uygulayabilirsiniz.
php artisan make:command SendMessage
app\Console\Commands dizininde oluşturulan dosyayı düzenleyin. Aşağıdaki kurgu Message modeli olması durumda oluşturulmuştur. Kendinize göre düzenleyebilirsiniz.
<?phpnamespace App\Console\Commands;use App\User;
use App\Message;
use Illuminate\Console\Command;class SendMessage extends Command
{protected $signature = 'send:message {user} {message}';protected $description = 'Send message to a user';public function __construct()
{
parent::__construct();
}public function handle(Message $message)
{
$message->send(User::find($this->argument('user')),$this->argument('message'));
}
}
Terminal komut dosyasında artık hazırız.
php artisan send:message 1 Mesaj