Conversation with Merlin [email protected] · Fri Nov 10 2023

how to add public github repository in my laravel project using composer

To add a public GitHub repository to your project using Composer, you can follow these steps:

  1. Open the composer.json file in your Laravel project.
  2. Add the GitHub repository as a dependency in the repositories section of composer file. If repository includes a composer.json file, you can directly require the package using its name and version. Otherwise, you can specify the repository URL directly.

Here's an example of how to add a public GitHub repository in your composer.json:

{ "repositories": [ { "type": "vcs", "url": "https://github.com/username/repository-name" } ], "require": { "username/repository-name": "dev-master" } }

Replace "username" with the GitHub username of the repository owner and "repository-name" with the name of the repository.

  1. After adding the repository and package to the composer.json file, run the following Composer command in your terminal to install the package:
composer install

This will fetch and install the package from the public GitHub repository into your Laravel project.

Please ensure that you have the necessary permissions to access the public GitHub repository and that the repository is publicly accessible.

Concepts Package Repository Types Composer packages notify-batch metadata-url, available-packages and available-package-patterns providers-api list provider-includes and providers-url cURL or stream options VCS Loading a package from a VCS repository Using private repositories Git alternatives Bitbucket Driver Configuration Subversion Options Package Hosting your own Private Packagist Satis Artifact Path Disabling Packagist.org Repositories# This chapter will explain the concept of packages and repositories, what kinds of repositories are available, and how they work. Concepts# Before we look at the different types of repositories that exist, we need to understand some basic concepts that Composer is built on. Package# Composer is a dependency manager. It installs packages locally. A package is essentially a directory containing something. In this case it is PHP code, but in theory it could be anything. And it contains a package description which has a name and a version. The name and the version are used to identify the package. In fact, internally, Composer sees every version as a separate package. While this distinction does not matter when you are using Composer, it's quite important when you want to change it. In addition to the name and the version, there is useful metadata. The information most relevant for installation is the source definition, which describes where to get the package contents. The package data points to the contents of the package. And there are two options here: dist and source. Dist: The dist is a packaged version of the package data. Usually a released version, usually a stable release. Source: The source is used for development. This will usually originate from a source code repository, such as git. You can fetch this when you want to modify the downloaded package. Packages can supply either of these, or even both. Depending on certain factors, such as user-supplied options and stability of the package, one will be preferred. Repository# A repository is a package source. It's a list of packages/versions. Composer will look in all your repositories to find the packages your project requires. By default, only the Packagist.org repository is registered in Composer. You can add more repositories to your project by declaring them in composer.json. Repositories are only available to the root package and the repositories defined in your dependencies will not be loaded. Read the FAQ entry if you want to learn why. When resolving dependencies, packages are looked up from repositories from top to bottom, and by default, as soon as a package is found in one, Composer stops looking in other repositories. Read the repository priorities article for more details and to see how to change this behavior. Types# Composer# The main repository type is the composer repository. It uses a single packages.json file that contains all of the package metadata. This is also the repository type that packagist uses. To reference a composer repository, supply the path before the packages.json file. In the case of packagist, that file is located at /packages.json, so the URL of the repository would be repo.packagist.org. For example.org/packages.json the repository URL would be example.org. { "repositories": [ { "type": "composer", "url": "https://example.org" } ] } packages# The only required field is packages. The JSON structure is as follows: { "packages": { "vendor/package-name": { "dev-master": { @composer.json }, "1.0.x-dev": { @composer.json }, "0.0.1": { @composer.json }, "1.0.0": { @composer.json } } } } The @composer.json marker would be the contents of the composer.json from that package version including as a minimum: name version dist or source Here is a minimal package definition: { "name": "smarty/smarty", "version": "3.1.7", "dist": { "url": "https://www.smarty.net/files/Smarty-3.1.7.zip", "type": "zip" } } It may include any of the other fields specified in the schema. notify-batch# The notify-batch field allows

getcomposer.org

The dependency management tool Composer provides multiple ways to include Git repositories within a PHP: Hypertext Preprocessor (PHP) project. In many cases, repositories have been created on Packagist, so requiring them with Composer is very straightforward. But what do you do when a repository has not been created as a package on Packagist? You use Composer to require the package directly from the repository. This article explains how. Note: Some of the terminology in this post is confusing because multiple words are used to describe different things. Here is a quick vocabulary list that will help: Project: The custom software you are building. This can be a website, a command-line utility, an application, or anything else you dream up. Package: Any third-party software you want to download and use within your project. It can be a library, Drupal theme, WordPress plugin, or any other number of things. Git repository: Also called the Git repo, this is the version-control host for a package. Common hosts include GitHub, GitLab, or Bitbucket, but any URL-accessible Git repository will work for this tutorial. Composer repositories: In a composer.json file, there is an optional property named "repositories." This property is where you can define new places for Composer to look when downloading packages. When adding a Git repo to your project with Composer, you can find yourself in two situations: Either the repo contains a composer.json file, which defines how the repo should be handled when required, or it does not. You can add the Git repository to your project in both cases, with different methods. Git repo with composer.json When a repository includes a composer.json file, it defines aspects of itself that are important to how Composer manages the package. Here is an example of a simple composer.json file a package may include: { "name": "mynamespace/my-custom-library", "type": "library" }This example shows two important properties that a composer.json file can define: Name: The package's namespaced name. In this case, "mynamespace" is the namespace for the package "my-custom-library." Type: The type of package the repo represents. Package types are used for installation logic. Out of the box, Composer allows for the following package types: library, project, metapackage, and composer-plugin. You can verify this by looking at the composer.json file of any popular GitHub project. They each define their package name and the package type near the top of the file. When a repository has this information defined in its composer.json file, requiring the repository within your project is quite simple. Require a Git repository that has a composer.json file After you've identified a Git repository with a composer.json file, you can require that repository as a package within your project. Within your project's composer.json file, you need to define a new property (assuming it doesn't exist already) named "repositories." The value of the repositories property is an array of objects, each containing information about the repository you want to include in your project. Consider this composer.json file for your custom project. { "name": "mynamespace/my-project-that-uses-composer", "repositories": [ { "type": "vcs", "url": "https://github.com/mynamespace/my-custom-library.git" } ], "require": { "mynamespace/my-custom-library": "dev-master" } } You are doing two important things here. First, you're defining a new repository that Composer can reference when requiring packages. And second, you're requiring the package from the newly defined repository. Note: The package version is a part of the require statement and not a part of the repository property. You can require a specific branch of a repo by choosing a version named "dev-<branch name>". If you were to run composer install in the context of this file, Composer would look for a project at the defined URL. If that URL represents a Git repo that contains a composer.json file that defines

opensource.com

Laravel is a powerful PHP framework and its slogan is The PHP Framework for Web Artisans. At our web agency we often receive questions about Laravel app web development. If you forgot the steps or Laravel commands during the installation of your projects, this setup tutorial is for you. Here is our Laravel tutorial for installing projects on Linux or Windows server from Github and other Git repositories. Table of contentsWhat is Laravel?Login With the Right Permissions (Optional)Clone Your RepoAccess Your Project DirectoryInstall the Project Dependencies from the ComposerInstall NPM Dependencies (Optional)Create a Copy of Your .env FileGenerate Your Encryption KeySome Practical Commands (Optional)Clean up your projectCreate an Empty Database for Your ProjectConfigure Your .env File to Allow a Connection to the DatabaseAdd the Tables and Contents of Your Database with Migrations or in SQLConclusionWhat is Laravel? Laravel is a popular and powerful PHP web application framework that makes it easy for developers to deploy modern, scalable, and secure web applications. One of the key advantages of Laravel is that it simplifies many common app web development tasks, such as routing, authentication, database management, and more. It also includes many pre-built components and packages that can be easily integrated into your application, such as caching, session management, and email sending. Login With the Right Permissions (Optional) If you are logged in as root or super admin on your server locally, make sure you change your user to the default web user for the Laravel project. Simply do this: Su yourusername Clone Your Repo Whether your project is hosted on Github, Gitlab, Bitbucket or other, it all comes back to GIT, so we can use git on our local machine or server to clone our project. git clone linktoyourpo.com/project name Note that you clone projects in 2 ways, one in HTTPS mode and one in SSH mode. PRO TIP: You can clone your project from a specific branch by doing git clone use this tag: -b nameofthebranch linktoyourepo.com/projectname Access Your Project Directory After cloning Laravel project from GitHub, a new folder with the name of your Laravel project should be created in your current location. You just need to access it by making: cd projectname Install the Project Dependencies from the Composer Each time you clone a new Laravel project, you have to install all the dependencies of the project. You need these packages to start the application. When we run the composer, it checks the composer.json file that is in your repo and lists all the composer packages your repo needs. As these packages are constantly changing, the source code is usually not submitted to git, thanks to the .gitignore that should always contain the vendor directory. So to install all the necessary source code, we run the composer with the following command. composer install You can also think about how to simplify and automate your workflow. Install NPM Dependencies (Optional) This is exactly like the previous step with the only difference being that it will allow you to install Vue.js, Bootstrap.css, Lodash and Laravel Mix etc In short, instead of installing PHP code as in the previous step, its a matter of installing the required Javascript (or Node) packages. The list of packages needed in this case are listed in packages.json file. If your project doesnt use vue.js, node or other you can skip this step, otherwise you have to do: npm install Others prefer Yarn, if thats the case, just do it. Yarn Create a Copy of Your .env File The .env files are generally not submitted to your repo, if this is not the case I invite you to correct this for security reasons. But there is an example env file and Laravel, which is a template of the .env that every Laravel project needs to start. So we will make a copy of the .env.example file and create an .env file that we can fill in with our configuration settings. cp .env.example .env Generate Your Encryptio

oshara.ca