Laravel console like rails - php

I have began to study "Laravel". I have already learned ruby on rails framework. Rails have console where you can create models and run all the commands your script runs. It is very useful and i am really used to this. I am interested if "Laravel" has anything like this, to create my objects and check if validations work correctly or run commands like
"Post.all" where post is my object to retrieve all data from database.

The Rails console is based on Interactive Ruby Shell (IRB) which is a read–eval–print loop (REPL) environment. There is an equivalent in Laravel (based off of psysh):
php artisan tinker
Note that 'Tinker' appears to be included in Laravel 5.7 (current at time of writing), but was removed in some previous versions. It can be installed with these instructions:
https://stackoverflow.com/a/41888190/1512654

Related

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');

What is the difference between artisan and composer from the point view of a laravel project?

I didn't know composer before laravel and i encountered them at the same time. So, I can't distinguish the commands of them, but memorize them.
What is the difference between php artisan and composer.phar and also the commands they run?
Can anyone help me on this issue? Thanks..
Composer is a package manager for php and artisan is a command line tool using php
Composer
- download libraries
Artisan
- run scripted commands like you would in bash
The reason to use artisan instead of direct php commands is that you have to implement certain functions so you get an universal feel to the commands. It will help with a lot of things like handling arguments. You could see it as a nice helper for writing great php command line tools.
Once your command is generated, you should fill out the name and
description properties of the class, which will be used when
displaying your command on the list screen.
The fire method will be called when your command is executed. You may
place any command logic in this method.
https://laravel.com/docs/5.0/commands
There is a basic difference in these two commands that they belongs to two different packages.
Composer: composer is a dependency management tool for php. It auto manages dependencies of your project according to your requirements and thus makes your project more distributable.
You don't have to package all the dependencies inside your application. And, if your dependencies are variable it is hard to manage them all within your application. So, composer does it for you.
So, your composer command operates this package. And, it can be used for any project whether it is laravel or other php application.
Artisan: This is the command line utility of Laravel. It comes integrated with your laravel installation.
You can perform operations on your laravel project using its commands. As it is a tool built over php. So, you need to execute its command over php-CLI. That is why you use the php before it.
And, you need to use artisan before it because this is the script name which operates the commands of this tool. If you see your laravel project directory it has a file named artisan inside the root folder. It is the file which bootstraps the laravel's command line code. Or, you can say it is like index.php of directory.
Hope I was helpful.

Laravel package development with dependacy package

Background
I am new to the Laravel Package.
In my Laravel application I usually run the following command in order to install Bican Rokes, change the config files, etc...
php artisan make:auth
php artisan migrate
Objective
However, this process is tedious, so I was wondering if it is possible to create a package capable of automatizing the process.
What I tried
To achieve this I read the Laravel documentation, which teaches how to create packages, but I was unable to understand if this is possible and if it yes, how it should be done.
Questions
Can a package be used to automate this behaviour?
If yes, can you provide it?
If not, can you explain to me what a package really is? (links to tutorials are welcome)
If I cannot use a package, is there any other way of doing this?
I am not pushing the sale of anything, nor do I know this guy. But this tutorial is a pretty good starting point for laravel.
Laravel Tutorial Series
if a separate package should be created or not will depend on volume of work you want to accomplish. a starting point can be a custom console command, and from with-in that command, you can call multiple other commands.. And from their you can extend it to do other things like editing files etc. If you don't know how to write a console command in Laravel, here is the link to docs: https://laravel.com/docs/5.2/artisan#writing-commands

Laravel 4: Any way to run PHP Artisan command in PHP code?

I'm fairly new on Laravel's technology regarding real-time application. I'm trying to make a notification system and from what I Google, using some kind of socket server is the best way.
So I'm trying to use this: https://github.com/BrainBoxLabs/brain-socket
But I have no idea how to run it on live server later, since I don't own the server itself I can't run commands like: php artisan brainsocket:start in terminal, so I need to figure out how to run that command by using php code?
Or if my method is wrong, how to use that brain-socket in live server?
You can do this with
Artisan::call('brainsocket:start', $args);
where $args is an array of arguments.
See the Laravel docs.

Run command in symfony2

I'm trying to create my first page in Symfony2 according to this tutorial: http://symfony.com/doc/2.0/book/page_creation.html. Can anyone please tell how should I run this command:
php app/console init:bundle "Acme\StudyBundle" src
I'm new to symfony and I have no idea what this means...
php app/console init:bundle "Acme\StudyBundle" src
is a shell command you're meant to run at the command line of the machine you've installed Symfony on. You change into the directory where you installed symfony, and run it -- how you do that is obviously operating system- and installation-dependent.
The command itself invokes the command-line version of your PHP interpreter (php) to run Symfony's console script (app/console) to initialise a new Symfony bundle (init:bundle) called StudyBundle, from the (pretend!) company Acme (Acme\StudyBundle) in the directory src.
For me, running it would look a bit like this (from Terminal, on a Mac):
Matt-Gibsons-iMac:~ matt$ cd Sites/Symfony
Matt-Gibsons-iMac:Symfony matt$ php app/console init:bundle "Acme\StudyBundle" src
Summary of actions
- The bundle "AcmeStudyBundle" was created at "src/Acme/StudyBundle" and is using the namespace "Acme\StudyBundle".
...
A word of warning, though: Symfony 2 is still very new -- not yet even officially released -- and while what documentation there is is okay, the docs are nothing like as complete or helpful to the beginner as the excellent, mature documentation for Symfony 1.4. Also, Symfony 2 best practices have yet to be established.
So, if you're a complete Symfony novice you might find Symfony 1.4 easier going, especially following the Jobeet tutorial. Even though Symfony 2 is quite a big change from Symfony 1, learning Symfony 1 will introduce you to a lot of concepts that remain familiar in Symfony 2, such as generating new code modules from the command line, like you're trying to do here.

Categories