Check config/assets are published or not in Laravel package - laravel

I have two questions which are quite related.
1) I'm building a Laravel package which will have a package config file. It can be published using php artisan vendor:publish command. Now in the service provider class of that package, I want to know that if that file has been published by the user or not. How can I do that? By simply checking file existence or is there any Laravel specific way for that?
2) In the view file of that package, I want to include a js file which is also there in that same package. How can I do that? Do I have to publish it first into Laravel's public directory and then include it? If possible I don't want to publish it.
Let me know if anything is not clear.
Thanks

Related

Can Laravel generate all mvc skeleton out of an existing table like that of cakephp's command cake bake all

I found laravel very interesting. But I'm wondering if there's any artisan command to generate all MVC skeleton files provided a database table all at ones. And how about separate generation of especially the model, given the table structure? or is there any alternative way to do the code generating?
You can create a migration file from the table via the package below.
https://github.com/Xethron/migrations-generator
Install it via : composer require --dev "xethron/migrations-generator"
Follow the package instructions, After connecting you application with the database simply run php artisan migrate:generate.
You will see number of migrations created via console message, You can also check your database/migrations folder for confirmation.
I didn't find how to do that, so I created my own code in order to create the models:
https://github.com/Triun/laravel-model-base
It is not super documented, but you can actually write your own addons in order to add custom business behaviors or include your own interfaces or traits to your models, with your own code.
And of course, reports and contributions are more than welcome.
I hope this helps.

External PHP Include in Laravel

We run a main website which is not made in Laravel. A specific script on this website however is made in Laravel. We need this script (or to be exact, a specific view inside of it) to fetch some resources from the main website (PHP files which mainly include HTML). When, inside the Laravel application, we try to include these resources, we can not - as they don't exist in the Laravel project workspace. This results in an error that the file does not exist. Attempting to climb out of the project (../../../file.php) does not seem to help either.
We're including it this way:
<?php
include '~/template/nav.php';
?>
We don't wish to include this file into the actual Laravel project, as that would require having to update it twice to ensure they remain equal. Is there any way for us to include this "external" file in our view? Every bit of research done seems to suggest adding it into the project, which would just cause twice the amount of administration on updates.
Cheers!
Just faced same problem. My Laravel Project is an API that need's to include outside php file. So what I did was specify entire path:
include($_SERVER['DOCUMENT_ROOT'].'/../../my_example_file.php');
$_SERVER['DOCUMENT_ROOT'] will lead you to Laravel's public folder.

Where is the Registrar Services in Laravel 5?

I added couple of fields to my user table and everywhere I read it said I also need to update the new fields in the app/Services/Registrar.php file. But I cannot find the Services folder anywhere! This is a new installation in Laravel 5 and here is the screen shot of my directory structure:
What happened to the Services Folder? When I test, I can see that the User::create() works but I dont know where its declared since I cant find the Registrar.php file.
I added couple of fields to my user table and everywhere I read it said I also need to update the new fields in the app/Services/Registrar.php file.
This was removed in Laravel 5.1.
https://laravel.com/docs/5.1/upgrade#upgrade-5.1.0
Secondly, the App\Services\Registrar class used in Laravel 5.0 is no longer needed. You can simply copy and paste your validator and create method from this class directly into your AuthController. No other changes should need to be made to these methods; however, you should be sure to import the Validator facade and your User model at the top of your AuthController.
You are using 5.1 version and it doesn't have such directory or service. This version uses AuthenticatesAndRegistersUsers traits for registering users.

Create a Resource Controller?

I'm trying to make a resource controller in my package but i'm not sure how to do it.
Normally I would use:
php artisan controller:make MyController
But how can I make it so this is created in my package?
If you take a look at php artisan help controller:make you will see that there is a path option, so I guess that's what you're looking for.
Another option would be to explore the workbench which will make things easier while developing a package

How to avoid using php composer dump-autoload with laravel 4?

I have uploaded my project on a web host and I use ftp to edit my code.
The problem is that I added models using eloquent for my database and to get it work I have to download my project dans run php composer dump-autoload then re-upload. Otherwise its say class not found ... Doing this all the time is just heavy.
Is there any other solution?
My webhost does not have ssh or any thing to connect to the server. Neither I can use rsync like stuff.
Maybe I should use an other framework than laravel4 to avoid using composer?
In your case, you should add your needed autoload directory to the ClassLoader::addDirectories array under /app/start/global.php. Laravel gives multiple ways to accomplish the same thing depending on your personal needs.
You can remove or not upload the bootstrap/compiled.php file.
I'm not sure if this completely fixes your problem, because I'm not sure if dump-autoload generates multiple files.
[edit]An other approach is to work on your local machine and upload after you are finished.
I'm not sure, sometimes it works, sometimes not...
But I upload:
bootstrap/autoload.php
vendor/autoload.php
vendor/composer/*
And I don't have a bootstrap/compiled.php

Resources