how to autoload jQuery package to Laravel with Composer - php

I'm just getting started with Laravel / Composer. I want jquery to load with the composer autoloader.
My composer.json file looks like this:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"frameworks/jquery": "1.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
],
"files":[
"vendor/frameworks/jquery/jquery.min.js"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
notice i've added jquery to the require list and have added the jquery.min.js to the autoload / files. It loads, but as plain text, not as a js file.
This has to be something stupid I'm doing, but I can't figure it out. How do I get the file to load properly?

You cannot autoload jQuery with composer, because that would mean you want to execute Javascript on the server with the PHP script engine. This will never work.
What you want to do is include jQuery in the page you are creating with PHP. Probably include it as a javascript tag that loads it. Which means you have to configure a way to make that jquery.min.js file available on the server for HTTP access.
The frameworks/jquery package does not have any suggestions on how to do this. It simply grabs the files and adds it to the vendor folder. If you want it made available to the browser you'd either copy it into the document root, setup a script that reads the file and sends it to the browser, set a symlink to it, or add an alias to that vendor directory. All of these solutions are not that nice, but if asked I'd prefer the copy step.
There is a components/jquery package that uses another package to allow easy configuration of where to drop the files. You should investigate that, read the README. It looks much nicer to maintain and will essentially do the copy step.

I might be wrong but composer is used to autoload php files. It allows you to call something with out including it. This is all on the server side. I don't think you can do what you are trying to do.

Related

Laravel artisan command not working

I've created my laravel project with create-project beacause composer install didn't work.
cd to my project and then, when I try to use php artisan list or any artisan command it just says:
Could not open input file: artisan
How do I fix this? the vendor file is in the project
My composer.json:
{
"name": "vendor_name/package_name",
"description": "description_text",
"minimum-stability": "stable",
"license": "proprietary",
"authors": [
{
"name": "author's name",
"email": "email#example.com"
}
],
"require": {
"barryvdh/laravel-ide-helper": "^2.0"
}
}
path to my project:
c:\wamp\www\project1
Inside vendor, no folder named artisan is showed
Use the project's root folder
Artisan comes with Laravel by default, if your php command works fine, then the only thing you need to do is to navigate to the project's root folder. The root folder is the parent folder of the app folder. For example:
cd c:\Program Files\xampp\htdocs\your-project-name
Now the php artisan list command should work fine, because PHP runs the file called artisan in the project's folder.
Now install the laravel framework
Keep in mind that Artisan runs scripts stored in the vendor folder, so if you installed Laravel without Composer, like downloading and extracting the Laravel GitHub repo for laravel, then you don't have the framework itself and you may get the following error when you try to use Artisan:
Could not open input file: artisan
To solve this you have to install the framework itself by running composer install in your project's root folder.
Have you tried to do a "ls" (linux) or a "dir" (win) to make sure you are in the correct folder?
Check if you have correctly installed php.
Run cmd or shell and try to run
php -v
I'm going to assume you have Windows as your OS.
Go to Control Panel -> System and Security -> System -> Advanced system settings.
Then go to Environment Variables, find "Path" and add
;your/path/to/php.exe
at the end.
Replace "your/path/to/" with your current php.exe directory (including C:\ )
EDIT
Try with this one:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"laravel/framework": "5.0.*",
"barryvdh/laravel-ide-helper": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php -r \"copy('.env.example', '.env');\"",
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}
I'm using windows 10, today is 31st dec, 2016.
I had the same issue, did a bit of a research and solved it.
First go to vendor directory from your laravel project directory and run this command:
composer install
if it further shows an error and asks for the composer.json file missing then:
cd ../
composer install
This fixed my issue!
I don't know if this has been solved, but I found this to be useful:
composer require laravel/passport --ignore-platform-req=ext-fileinfo

Composer update "PHP Warning: unexpected character" error message Laravel-4

I do not understand where this error is coming from. I first noted it after installing a third party package, and thought that was the problem. Uninstalling the package made no difference. Reverting to an earlier version of Laravel also had no effect. (So now I'm back to the current version, 4.2.8.)
Here is the full error message in response to $ composer update -- the error is repeated 7 times, right after "Generating autoload files":
PHP Warning: Unexpected character in input: ' in phar:///usr/local/bin/composer/src/Composer/Autoload/ClassMapGenerator.php on line 118
This appears to refer to a corrupted piece of code in composer itself, rather than a corrupted file in the Laravel tree. My copy of composer lives in /usr/local/bin and the only file in that directory is composer. The warning appears to suggest that composer is a directory, but of course it's not. There is nothing on line 118 in composer itself.
I have no idea how to fix this, or how important it is, or how to find where the problem is. Do I need to reinstall composer?
Thanks for any help.
In response to a comment asking about whether composer.json is the problem, here's my entire composer.json file. I can't identify any errors there:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.2.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"app/libraries"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
And here's lines 116-123 from composer.lock -- could the problem be here? :
"autoload": {
"psr-0": {
"Whoops": "src/"
},
"classmap": [
"src/deprecated"
]
},
Thanks.
Problem solved simply by running
composer self-update
Thanks much to help from Marwelln and WereWolf.

Laravel Error with str.php in vendor directory

For some reason I started getting this error after a few days. I didn't change anything from the time my Laravel application was working to the time it threw this parse error:
Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /home/fzystudi/public_html/vendor/laravel/framework/src/Illuminate/Support/Str.php on line 7
Here is the site live with error.
Here is what I tried for solving the errors:
I wiped everything clean and installed laravel again. Same error. So I then did composer update. Still no change. I did composer update again and still no change.
I also downloaded the developer version and stable version. Still no difference.
I cloned the exact file from str.php and the file is the same on github as it is in my app on my ftp server.
I uploaded to hostgator and A2 hosting. Same error on both sites.
Here is the thread on the laravel forum I posted. No one has been able to help yet.
What seems to be the cause and what is the fix?
This is my controller:
<?php
class SiteController extends BaseController {
public function __construct() {
//parent::__construct();
$this->beforeFilter('csrf', array('on'=>'post'));
}
//homepage for our store
public function getIndex() {
return View::make('site.index');
}
}
My composer.json:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/laravel": "4.1.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
This sounds like you're getting the bleeding edge version of Laravel which has started to make use of traits. I'm assuming line 7 of the Str.php file in your vendor directory is something like this?
use MacroableTrait;
You should check your composer.json file to make sure you're depending on the stable release of Laravel 4.1.
"laravel/laravel": "4.1.*"
You may need to delete your vendor directory again as well as the composer.lock file. If you don't remove the lock file you'll just re-install the same dependencies again. Once installed you can check the version you have by running artisan --version from your command line in the installed directory.

Getting white screen of death on deployed Laravel app

Earlier today my Laravel app on Fortrabbit was working fine but after pushing to the app white pages started to be displayed instead of any content. I can still directly access any assets by explicitly specifying the path but if I try to access my index page or any other that work both locally and on previous versions of the application I get a white screen with no content.
I've tried removing the /vendor directory and composer.lock and updating composer to get a fresh start. I've also looked into the logs given by the Fortrabbit service in the php and apache directories and neither are reporting errors. I've also looked into the logs for Laravel and this also didn't provide any error messages that could help me debug the issue.
Was wondering if anyone had experience with this issue and could offer steps to attempt to resolve it, thank you!
Notes:
I'm using Laravel v4.1.*
The commit that began causing the issue contained no changes to PHP code (only SCSS files)
I've run php artisan dump-autoload already
I can run php artisan tinker and interact with the MySQL database just fine with my models
My composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"way/generators": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
}
}

Composer not updating required library

I'm using the Laravel framework and wanted to include a library from GitHub. This is my full composer.json file:
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.0.*",
"intervention/helper": "dev-master" <- this is what I've added
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/validators",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
I've added "intervention/helper": "dev-master" under the require directive and when I do composer update on my local copy of the website, everything works fine and I can use the library.
I did a git push and pull to get it onto my live server, and when doing a composer update it doesn't download this library. This is the entire output of the command: http://pastebin.com/UgPNTaDw
I also tried composer install and composer update for a second time but neither worked. I've also verified that git retrieved the new composer.json file on the live server, and it has.
Why isn't composer recognizing the changes and downloading the library?
Besides the fact that your log does exactly tell you the "missing" library was downloaded, I have some general comment:
Are you sure you want to use EVERY library in DEVELOPMENT quality? Because that is what you enabled with the "minimum stability" flag: You are allowing EVERYTHING in possibly broken state from whatever development branch the libraries provide.
And the second thing is: You are supposed to update only once, on your development machine! Then test that everything still is working, and commit the composer.lock file!
Then push and pull that change to wherever you need it, and there only composer install - because you probably want the exact SAME library versions that you tested with, not anything slightly newer with possibly broken commits.
If you only want to use that particular library as development version, you should add that flag to the version requirement:
"intervention/helper": "dev-master#dev"
On the other hand, this library has released versions, so it might be better to require them...

Categories