Downloading the Laravel each time when creating the project? - php

In the console I will type below.
Composer create-project laravel/laravel "MyLocation" --prefer-dist
This will start downloading everything.
Question: Can't we copy the framework from previous created project ? Is that necessary every time to download everything from scratch ?

You can copy the existing Laravel projects if you want. But, you may need to modify too much of the parts for your new project.
Downloading a new one is the better option. In my personal opinion, make a laravel base project then push it into your git repository and whenever a new project starts, you only need to pull or fork from the repository and start building.

Related

Multiple projects - 1 package

I'm working with multiple projects, each one separated from the others in my server. So my problem is that I have a Core project that have all the functions I need, and in Laravel projects it's annoying to copy/paste everything every time. I was thinking to create a package and install it in all my Laravel projects via composer, but it bothers me the fact that every time I want to add a feature or perform a minor bug fix, I will have to do a composer update in every project (I have more than 20 actually).
I just came up with some ideas, let me know what do you think about it and if you will use some different idea:
Create a Model/Class that includes my main php core library directly from the server (Remember that I have all the projects in the same server). I will just need to call the Model/class and it will import all the functions. I will just need to keep updated the main library code every time I perform a minor bug fix or any new implementation.
Create a package where inside will have all code I could need to use in all projects (main library). This would be perfect, since I want just use the composer install command get the package installed in my project. I'm not concerned at all with this solution, because I have more than 20 diferent projects and I will need to do more than 20 composer update every time I perform a minor bug fix or new implementation.
The last one is to do a generic composer where it contains all the packages I would need (almost all the projects use the same composer.json) and create a symlink between all the projects. I will install the packages in one folder and keep that updated everytime I perform some new task, and the symlink will keep the folders updated in every project.
What do you think about that options? I think I will go for the 3rd one, but wanna know your opinions or if you have the same problem and works with other solutions.
Or you could create a bash script that runs composer update for all of your projects.
#!/bin/bash
cd /var/www/website.com && composer update package/name
cd /var/www/website2.com && composer update package/name
cd /var/www/website3.com && composer update package/name

What files and folders to copy when moving Laravel Project

I'm kinda still finding my way around the Laravel development framework. I want to use a Sample Project Here for my learning
Now the project was done in Laravel 5 and i'm trying to use the Latest 5.5 Laravel.
How do i go about this and what files and folders do i have to copy to my Laravel 5.5 project to get this working.
The file and code structure has changed quite a lot from Laravel 5.0 to Laravel 5.5.
If you are wanting to use that project on Laravel 5.5 then you would need to go through the update process for each version until you reached Laravel 5.5. These can all be found in the Laravel documentation for the respective version.
An easy, and better approach, would just be to incorporate this into your project manually.
SB Admin is just a theme based on Bootstrap and so you can just incorporate it into your app as you would Bootstrap.
You can download the source for SB Admin here - https://startbootstrap.com/template-overviews/sb-admin/
You can also check out the source on GitHub if you need more of an idea on how to use it on specific pages - https://github.com/BlackrockDigital/startbootstrap-sb-admin
If you really want to use that project to learn Laravel then you can. As you're still new to Laravel, I wouldn't bother updating it (you'd likely be in over your head).
To get started with the project, just follow the instructions on their repo - https://github.com/start-laravel/sb-admin-laravel-5:
Clone the project git clone https://github.com/start-laravel/sb-admin-laravel-5.git
Switch into the newly created folder
composer install to install Laravel and the required dependencies
npm install
bower install

Composer: Updating a Project Created with `create-project`

Does composer provide a way to update the package a project was created with? i.e., if I create a new laravel project with the following
composer create-project --prefer-dist laravel/laravel blog
Composer will grab the latest version of the laravel/laravel package, unarchive it into the blog folder, and then run composer install from the blog folder.
What I want/need to know is, does composer provide a way for me to update the laravel/laravel package that was downloaded to the blog folder? I know I could run composer update inside the blog folder myself, but this will only update things listed in the compser.json's require property — it will not update the unarchived laravel/laravel in blog (or will it?)
As far as I know it's not really possible.
Imagine that you create a new as example Laravel project.
The composer create-project creates the skeleton with all initial routes in your configuration etc.
From the very very first moment you are starting to change the default routes, removing the default controllers and changing the default views, your project would be out of sync. because meanwhile laravel changes the skeleton to newer versions with some new default routes etc or event changes directory structure.
It would be really hard to merge those changes over your existing application.
A better solution would be to follow the "Upgrade guides" (laravel: https://laravel.com/docs/5.4/upgrade) and then just commit those changes to your own project.
If you want to upgrade to a new laravel version, you can always follow the upgrade guide for your specific version:
Laravel 5.8 to 6.0
Laravel 5.7 to 5.8
Laravel 5.6 to 5.7
Laravel 5.5 to 5.6
If you are more than one version behind, you need to apply the previous upgrade guide. So if you are on 5.6 and want to upgrade to 5.8, you need to follow the guide for 5.6 to 5.7 and then from 5.7 to 5.8.
The guides are pretty helpful: they tell you which package must be updated to what version and inform you about deprecated methods which will be removed in the upcoming versions.
Another method which you can use to upgrade to new minor versions is to just look at the differences from one laravel release to the next. That way, you can see what exactly has changed and which files are new (configuration files for example which you can copy and paste into your project as the default composer create-project command would do).
As for the current version, you can see the commits since last release here: v5.8.30 to 5.8
Directly under the headline for a release, there is a small link labelled "36 commits to 5.8 since this release" which will take you to the link above, just for the latest version.
That's not the goal of composer, that just manage your packages.
You should see composer create-project just as a shortcut of git clone + composer install. If you need to deploy your application you've multiple options, from a simple git pull, to more advanced deployment tools like Capistrano. But composer isn't one of these tools.
I just needed to do this, and I couldn't find anything simpler than a git clone and a git pull (as #Federkun). Maybe an alternative would be to publish a phar file for the project and download that?
I can see db-ping does this. It's based on joomla/using phar. Here is the main file for building, inspired from joomla's file.

Laravel reusing the framework

I am new to laravel , composer and frameworks.however i have managed to install laravel on my pc via composer. and i have created a project with it using
composer create-project laravel/laravel your-project-name --prefer-dist
But i got a directory with my projectname on my current working directory with plenty of files in it.
I need to know wheather i could use this same files by copying the files in the folder and using this as my base for all my other projects..or do i need to run the composer command every time? Even if i run it i gets the same files, which i got now right? So could i just backup the files in the folder i got and use it as my base files?
Well unless you don't have an internet connection there's no point on creating a backup.
Laravel is modular and has external dependencies, so whenever you are creating a new project with composer you are fetching the most recent modules and the most recent Laravel version. But if you use a backup version you might be developing for an outdated version with critical bugs.
Another cool thing is that if you work on different computers, like you have one at work and another at home you don't have to be carrying your backup so you can start a new project by just doing:
composer create-project laravel/laravel your-project-name --prefer-dist
Also I never tested, but I think it takes more time copying a brand new Laravel install with it's dependecies than using composer.
Composer Offline
Another nice thing about using composer is that it stores everything in it's cache. So imagine this scenario we have an internet connection and create a new Laravel app
$ composer create-project laravel/laravel APP1 --prefer-dist
Now disconnect your internet, create another folder and install Laravel again
$ composer create-project laravel/laravel different-APP2 --prefer-dist
When you run the second time and since you don't have internet it will fetch everything from composer cache, but they will be two completely different applications with their own app names and their own application keys
You could use this files again, but you won't get the same files running the command every time, since the latest version of the laravel project and its dependencies are downloaded.
The project files are updated regularly. So if you don't have limited bandwidth, you should just create a new project every time.

Zend Framework 2 and source code repository

We created a ZF2 project with skeleton app and it works fine for a simple test application. Now we are working on a real project. My question is what we should store in the repository (SVN), the whole project structure or just the new source code? ZF2 comes with a vendor directory which is almost 31MB in size (which has the ZF libraries). Should we store the whole vendor folder in SVN?
This is the first time we are using PHP and ZF so are not clear in how we will deliver the complete project to production from SVN. Also what is the build process if at all exists. Any clues/links to "ZF2 project packaging" is appreciated.
No, don't include dependencies in your repository! Putting your dependencies under version control doesn't do any good, it just blows up your repo for no reason.
You want to add the skeleton to your repository and your own library but definitely not the framework or any other dependencies.
The way to go is to use composer for dependency installation and some kind of build tool like Phing to automate installation of your project.
See the relevant chapter on phptherightway for more information on how to build your application.
The most simple build process doesn't even need a build tool
checkout your project from SVN/git
run php composer.phar install to install the needed dependencies (defined in your composer.json)
But most probably you want to do some more stuff like setup up the environment, deleting some files, etc.
A word about ZF packages. They're not available from packagist but you can install them with composer anyways. You just have to add the dedicated repository to your composer.json as described here: http://framework.zend.com/downloads/composer

Categories