Do composer commands manually - php

Hello I want to connect a payment gateway in my laravel project. I can do that with composer but This script is located on the host and I do not have access to SSH.
Do you know how can I do these two commands manually?
composer require econea/nusoap:dev-master
php artisan make:controller siteController

Add the package to the vendor folder
Add a reference in \vendor\composer\autoload_namespaces.php
Add a reference in \vendor\composer\autoload_psr4.php
Work automatically now when the vendor\autoload.php is called
php artisan make:controller siteController
This will create a controller, The created can be seen at app/Http/Controllers.
Used for a create a new controller without a composer:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class siteController extends Controller
{
//
}

Related

Controller does not exist using Laravel 5.6

I created the Laravel project and I uploaded it into a shared server. Inside the server, I tested the application some controllers are not working but in the local, I tested it's working without issues.
When I tested the application in server it's saying
ReflectionException (-1)
Class Asset_Management_System\Http\Controllers\SublocOneController
does not exist
I don't know what was the issue please help me to fix this issue.
Controller File
namespace Asset_Management_System\Http\Controllers;
use Illuminate\Http\Request;
use Asset_Management_System\MainLocation;
use Asset_Management_System\SubLocationOne;
class SubLocOneController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
}
Web.php file
Route::resource('SubLocationOne','SubLocOneController');
Try to connect via ssh to the server and run in the root of the site:
composer dump-autoload
Are u renaming the app file in laravel structure with Asset_Management_System ?
basically if u make controller with this path :
App\Http\Controllers\[YourControllerName];
1.1 just do this :
namespace App\Http\Controllers;
In other case, you can use composer dump-autoload in terminal inside your directory.
Typo SublocOneController and SubLocOneController?

Laravel: Edit file in the vendor directory

I am working with laravel and I have installed a package using composer by running this command composer require mailchimp/mailchimp=~2.0.
After that I got a folder 'mailchimp' in the vendor directory. In there, there is a file named Mailchimp.php that I have to modify, but based on some old posts here, if I modify the file, any time I run the command composer update, I will loose my changes in the file, just because it is located in the vendor directory. So is there any option for me to solve this problem ?
I tried using the command php artisan vendor:publish but I do not get the expected results.
You can create a custom class which will extend the Mailchimp class and override the function you want. Then use the custom class in your code.
use DrewM\MailChimp\MailChimp;
class CustomMailChimp extends MailChimp {
...
// The function you would like to override
}
Then use it new CustomMailChimp(..)

How can i rename laravel controller with command line interface(CLI)?

I created controller which name is Home but I want rename it with HomeController. Is it possible in laravel?
Example:
class Home extends Controller { }
I Want to rename it like
class HomeController extends Controller { }
I Want to do it with CLI.
You can't use artisan, but you can do it manually. But it's not just a simple rename.
You have to:
Rename the PHP file.
Edit the PHP file to give the class the new controller name (the class name and the file name must match)
Change any code that uses that old class name to use the new class name
Edit the autoload files to load the new controller file:
vendor/composer/autoload_static.php
vendor/composer/autoload_classmap.php
You have to do it manually, there is no any command available to updated controller name.
Make a new Controller with the new Name.
php artisan make:controller NewController
or
php artisan make:controller NewController --resource
//if it is a resource controller
Now copy all contents from Old Controller to NewController.
Then edit all routes (in web.php) to that Controller.
forget CLI why not try rename the controller using 'AS'
use app\MyController as MyControl;
I think doing composer dump-autoload this regenerates the files :
vendor/composer/autoload_static.php
vendor/composer/autoload_classmap.php
You can assess the file using nano command or vi, it depends on your machine. it basically an editor the enable you to change the content of the file.

How to group Controller using route namespace Laravel

I am working on laravel project i have completed my admin panel and my all conrollers are in namespace App\Http\Controllers and everything is working perfectly fine now but i want to move all my Controller in folder AdminController for making everything more clear and smooth(Kind of HMVC technique).For this I add namespace on route which I did something like this
Route::group(['prefix' =>'admin','namespace'=>'AdminController'], function ()
{
/// all route
});
and i move all my conrollers in folder AdminController.Now its giving me error Cannot redeclare class Chemist\Http\Controllers\RoleController
Note: My baseconroller are in director App\Http\Controllers and all other controller are in App\Http\Controllers\AdminController
Create custom controller dir like
php artisan make:controller subDriectory/YourController
php artisan make:controller subDriectory/YourController --plain

How do I instruct artisan to save model to specific directory?

I'm using Laravel 5. I have created a /Models directory under the /App directory, but when generating the models using Artisan it's storing them under the App directory.
I have searched the documentation to try and find how to specify a different path name, but to no avail:
php artisan make:model TestModel
How do I instruct artisan to save the model to specific directory?
Create a Models directory or whatever your want to named it, put it in inside app directory. The Directory structure should look like
laravel-project
/app
/Console
/Events
/Exceptions
/Http
/Jobs
/Listeners
/Provider
/Models
Then You just need to type artisan command for creating models inside Models directory
php artisan make:model Models/ModelName
After Creating Models your namespace inside model classes will be
namespace app-name\Models\ModelName
You can access this model in inside your controller
use app-name\Models\ModelName
In Laravel 5.4 or later
You can create as below
> php artisan make:model "Models\userModel"
here Models is directory name and userModel is model name
Use " (double quotes) or ' (single quotes) to create model
For those using Laravel >= 5.2
It is possible to generate a model in a subdirectory using built-in Artisan generators by "escaping" the backslashes in the FQN, like so:
Laravel 5.2
php artisan model:make App\\Models\\Foo
Laravel 5.3
php artisan make:model App\\Models\\Foo
(the difference between 5.2 and 5.3 pointed out by #Khaled Rahman, thanks!)
Commands above would create Foo.php file in the app/Models directory and update the namespace accordingly.
Hope that helps.
If you want to specify the path when generating a model, you can use the Laravel Generators Package. You can then specify the location using the --path option like so:
php artisan generate:model TestModel --path=my/custom/location
You can override the default Laravel command with this console class
<?php
namespace App\Console\Commands;
use Illuminate\Foundation\Console\ModelMakeCommand;
class ModelMake extends ModelMakeCommand
{
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\\Models';
}
}
The next time you make a model
php artisan make:model Example
your class will be placed in
App\Models\Example.php
Edit: Laravel 8 natively support this. I copied this snippet from somewhere, I just can't remember where to credit.
You can simply use this (for Laravel 5.3+):
php artisan make:model your_path/model_name
If you don't specify a path it will use main 'app' folder as root. So you can navigate from there.
Models/Folder1/MyModel means app->Models->Folder1->MyModel.php
This works for actual Laravel version, 5.6.28, on Windows 7
php artisan make:model App\Models\NewModel
Note: Do not use double escapes ('\\')
This generate the file App\Models\NewModel.php as follows
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class NewModel extends Model
{
//
}
In Laravel 8+ with default Models directory it can be achieved like bellow.
php artisan make:model App\Modules\ModuleName\Models\ModelName
It generates model file in directory
app/Modules/ModuleName/Models/ModelName.php
<?php
namespace App\Modules\ModuleName\Models;
use Illuminate\Database\Eloquent\Model;
class ModelName extends Model {
...
}
}
Add this line in composer.json file if it is not defined.
"autoload": {
"psr-4": {
"App\\": "app/",
//...
}
Then in your terminal do;
php artisan make:model Models/your_path/model_name
Controller path (ApI/Admin)
Model path(Model/Admin)
php artisan make:controller API/Admin/PlanController --model=Model/Admin/Plan --resource

Categories