Laravel 5 package installation - laravel

I want to install a laravel package but don't have any idea how to do it.
It is the Admin Architect package that I want to install.
http://docs.adminarchitect.com/Getting_Started
This is the getting started page, if you scroll down to Zip archive (Public way) you will see the installation.
They say that you have to extract it in the package directory. But I do not have a package directory in my laravel 5.1 project.
Does someone know if you have to make one and put all the files that I have in there?

You need to start at the Via Zip archive (Public way) section.
The way to do this is completely up to you. The best way is probably to create a packages folder in your main Laravel directory along with app, bootstrap, database directories etc...
Unzip the contents of the zip package and then add the required item to your repositories in your composer.json
"repositories": [
...
{
"type": "git",
"url": "./packages/administrator"
}
...
]
This will add the repository which contains the package terranet/administrator as long as the url is correct. You might have to modify it to get it to work correctly so that when you run composer require terranet/administrator, it will be able to actually find terranet/administrator from the repository.
From there, simply follow the rest of the instructions (adding the service provider, etc...).
The reason other answers are not working is because the package terranet/administrator is not available publicly and you need to add the repository to your composer.json file for that to become availble. You can see all packages available publicly by going to packagist.org where you will see searching for this package yields some results but not the one you are looking for.

I don't know if you missed the instruction on the documentation:
Open your terminal:
cd yourproject
then run:
composer require terranet/administrator
Add service provider in config/app.php file.
'providers' => [
...
Terranet\Administrator\ServiceProvider::class
]
Run this command to publish assets:
php artisan vendor:publish
OR
php artisan vendor:publish --provider=Terranet\\Administrator\\ServiceProvider to publish only administrator's files.
Optionally to create new administrator user run:
php artisan administrator:create
Finally open config/administrator.php and make settings

If you have composer installed you could run the following from your program directory:
composer require terranet/administrator
After the package installed, add a new service provider to the providers array in config/app.php file.
'providers' => [
...
Terranet\Administrator\ServiceProvider::class
]
Then, publish package's assets by running:
php artisan vendor:publish
OR
php artisan vendor:publish --provider=Terranet\\Administrator\\ServiceProvider
to publish only administrator's files.
Optionally you can run
php artisan administrator:create
to create new administrator user ->All this taken from the link you provided.
Update
The problem with minimum stability can be fixed using this link for reference:
Tell composer you want to use stable whenever possible:
"minimum-stability": "dev",
"prefer-stable" : true
This basically means it will always use stable UNLESS there is no way to install a stable dependency, and therefore use dev.

Related

How to run a Laravel project that is downloaded from a cPanel?

SOLVED: My machine didn't have MySQL installed and was having a hard time installing it and I still do.
I recently downloaded a Laravel project from cPanel and I wish to work on it. But when I try to run the project I get "500 server error".
After searching on Google, I tried the following steps
composer update --no-scripts
php artisan key:generate
php artisan migrate
This does not seem to be doing anything. How do I run the project on my local machine that I downloaded from the cPanel?
You may want to see what that error is in the log file:
Log file location:
/storage/logs/laravel.log`
The laravel.log file mentioned above may have a date with it on the name.
The 500 error is because the stack trace is turned off in the .env file with APP_DEBUG=falsewhich may be by design since it's on a live server.
Download the files in "public_html" folder and project folder(in my case it is "LMS" folder - refer screenshot).
Export the database from phpmyadmin in cPanel which is used in Laravel project
Go inside the Project folder(in my case LMS folder) and delete all the content inside the "public" folder. Then you will have an empty public folder inside your project folder(LMS folder)
Now copy and paste all the content inside "public_html" folder that is downloaded from cPanel into the previously emptied "public" folder inside the project folder(LMS)
Import the exported database to locally created database
Change following lines in index.php file which is inside the local "public" folder
These two lines
require __DIR__.'/../LMS/vendor/autoload.php';
$app = require_once __DIR__.'/../LMS/bootstrap/app.php';
into these two
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
Notice that we have removed the "LMS" in the paths
Go to the .env file in the project root and change these settings that matches to your local environment
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lms_trends_new
DB_USERNAME=root
DB_PASSWORD=root
//Only for MAMP users
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
Run following commands
$ php artisan config:cache
$ composer dump-autoload
Finally run your project with following command
php artisan serve
First , Download the database from cpanel which is used in laravel project .
Then follow any one step below .
Upload the database in your localhost mysql .
then Change your env files as per your local system .
Install composer using following command .
composer install
Then update the compsoser From your composer.json file .
Composer update
composer dump-autoload
Now run php artisan serve
If you find any difficult in the first step , follow the second one.
Install new laravel project using following command .
`composer global require laravel/installer`
Create new project Laravel
`laravel new projectname`
Then just copy paste the directories app/ , Resources, /Public , /config .
Do not touch anything inside config/config.php
Just change the database name and username, password in .env file ..
Then run
php artisan serve
If you still cant able to do it , comment here

Laravel: Composer update when dependency is not yet installed

I require a dependency on my local environment. I add it's service provider and all is fine. The composer.json has this script
"pre-update-cmd": [
"php artisan clear-compiled"
],
When I push the changes to production, I try to run composer update but because of that script artisan fails with an error since the dependency is not yet installed and therefore the service provider I added in config/app.php is not there yet.
What is the best approach to situations like this? Just remove the pre-update script?
Hmmm interesting problem
What are you typing in for the service provider in your app.php
Have you tried removing your service provider and then running composer update and re-adding it after the dependencies have installed?
Interesting problem,
Please check your json file with
composer validate from your working directory.

moving Laravel project between computers

I have been working on a laravel5 project on a computer , but now I want to continue on an other, but don't know how :(
I'm using wampserver and the project is in the "www" folder, this is the error I'm getting when trying to open the project: " Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request"
Your error message is very vague, so it is hard to pinpoint the cause. I assume you just copy pasted all of the project files
Try these steps:
Make sure you copy all of the project files including the hidden ones(.env).
Prepare your destination computer as in http://laravel.com/docs/
Check you have all the necessary PHP extensions available in php.ini as in above link requirements. Also, watch your PHP version!
Install composer https://getcomposer.org/doc/00-intro.md
When copied, go to your destination folder and run composer install.
Run php artisan key:generate from the command line.
Run php artisan cache:clear from command line
http://php.net/manual/en/install.windows.commandline.php
Make sure your webserver is serving pages from project/public folder.
If laravel is failing, check the log file to see the cause
your_project/storage/logs/laravel.log
Copy the project folder and navigate terminal/cmd
just run following commands.
Create database and place the same name at .env file in laravel project folder
1. composer install
2. php artisan key:generate
3. php artisan cache:clear
4. php artisan migrate
UPDATE: If you're getting
Whoops, looks like something went wrong
in app/config/app.php, set debugging as true with:
'debug' => env('APP_DEBUG', true)'
If you're getting the error
No supported encrypter found. The cipher and/or key length are invalid
for some people it worked to do cp .env.example .env before (2).
You would also have to create new storage link, because Laravel uses absolute path inside it.
php artisan storage:link
https://stackoverflow.com/a/32722141/3982831 Please follow this to resolve your problems. All people forget about permissions on folders.
After you have done as Ademord answer, you might need to use refresh to your WAMP, XAMP or any other development stack you are using. I had the same issue plus changes were not reflecting in the front end. For example new routes in the web.php were not updating.

Issue Deploying with Laravel Forge

I am trying to deploy a Laravel PHP Project with Laravel Forge. I have connected to my repository on github correctly. However, when I hit deploy, if I go to the public IP for the site, I just see:
"No input file specified."
on the page.
I do not know why it is exhibiting this behavior.
If I go to the latest deployment log, I see:
/home/forge/.forge/provision-433327.sh: line 1: cd: /home/forge/default/laravel: No such file or directory
fatal: Not a git repository (or any of the parent directories): .git
Composer could not find a composer.json file in /home/forge
To initialize a project, please create a composer.json file as described in the http://getcomposer.org/ "Getting Started" section
Could not open input file: artisan
However, I do have a composer.json file in my laravel folder....
Any ideas? Thank you in advance.
It looks like the /home/forge/default/laravel directory doesn't exist. Could you ssh in and verify that the directory exists?
These are the commands that the default forge deploy script runs:
cd /home/forge/default
git pull origin master
composer install
php artisan migrate --force
It looks like your deploy script is navigating to /home/forge/default/laravel instead.

How to automatically run the migrations in a Laravel package?

I just installed Cartalyst's Sentry 2 in a Laravel 4 application but I found out that I have to run that package's migrations separately by specifying --package=cartalyst/sentry, which makes automatic deployment impossible.
Is there a way to run php artisan migrate and have it run Sentry's migrations as well?
After Laravel 5 there is a better way to solve this:
Create your migrations in package's
/database/migrations folder
.
After that, in package's service provider create a boot method, referencing the migrations folder
public function boot()
{
$this->loadMigrationsFrom(__DIR__ .
'/database/migrations');
}
Now, on the top level folder (the main app, which required this package), you can run the default migrate command ( php artisan migrate ) and it will automatically find the packages migrations througth the loadMigrationsFrom method
ANSWER COPIED FROM:
http://voerro.com/en/tutorials/r/developing-and-distributing-laravel-5-packages/3
What I usually do in a scenario like this is publish the package migrations though the command:
php artisan migrate:publish vendor/package
This copies the migration files from any given package to your migrations folder.
I created a composer script to replace php artisan migrate ...... The script runs my migrations and the vendor's migrations everything at once.
My composer scripts is
"scripts": {
"migrate": [
"php artisan migrate --env=$LARAVEL_ENV",
"php artisan migrate --package=\"cartalyst/sentry\" --env=$LARAVEL_ENV",
"php artisan migrate --package=\"mrjuliuss/syntara\" --env=$LARAVEL_ENV",
"php artisan migrate --package=\"filmoteca/static-pages\" --env=$LARAVEL_ENV"
]
}
Then you can run the migration with LARAVEL_ENV=prod composer run-script migrate
To pass parameter to the script I use environment variables. In the previous example I set the environment variable LARAVEL_ENV to prod so the migration use the production database connection.
You can always create a alias in your local machine to short the command. For example alias migrate="LARAVEL_ENV=local composer run-script migrate"
I think this approach is good because when you are going to add a new package to your composer.json and this package has a migration you add the package and the package's migration in the same file. So, you do not forget add/remove the migration of a package.
This is a complete composer.json with the script
The 3rd party package must declare a Service Provider, that declare migrations.
As you can see at https://github.com/laravel/passport/blob/9.x/src/PassportServiceProvider.php#L80:
protected function registerMigrations()
{
if (Passport::$runsMigrations && ! config('passport.client_uuids')) {
return $this->loadMigrationsFrom(__DIR__.'/../database/migrations');
}
}

Resources