I am trying to include this module: https://www.npmjs.com/package/react-datepicker-component with react into my Laravel Framework.
I went on to using npm to install it but I am getting no where after that.
I could use some direction. Has anyone tried using NPM for Laravel other than for Laravel Elixir?
I was stuck with this same issue for about an hour trying to pull in the inputmask node package.
The only way I was able to get it included was by attaching it to the window object in app.js (similar to what bootstrap.js does)
window.InputMask = require('inputmask');
If you don't want to load it every time (as it would with app.js) you can create a separate js file that contains only the line of code above and load that on select pages. I feel like there has to be a better way, but this is the only way I've found to make it work.
Related
in the last months I made some great progress using vue, and just a couple of days ago a friend asked me if I can do a little plugin for his page, that is made in pure PHP. I made a vue.js component, call it test.vue . It is Single File Component with script and template all togheter. Now, I tested it on my local enviroment on an laravel App the I was developing, and it works fine. But I don't understand how I can add it to the php page of him. In my App, I got NPM running and recompiling all my jss and css, but now that I have this single file I kind of lost the direction.
How can I run the single file component in a out of laravel php page? In laravel I just register the component in my app.js, do the npm mix and then just add the component markup into a blade view and everything works..
Some help will be much appreciate
Laravel noob here, I'm developing in Homestead.
Right now, if I want to edit something in my CSS, I edit app.scss(located in resources/assets/sass) then recompile my css with Mix. (npm run dev)
I don't know if this is the correct way to edit your css, but the last time I edited something, it worked. But now it doesn't and I'm confused.
I would also appreciated it if someone would tell me what's the use of _custom.scss and _variables.scss in sass folder.
This is the correct way. However, you need to run npm run dev each time you make changes to the app.scss file. Better way is to use npm run watch which can keep watching changes to your script files.
_variables.scss and _custom.scss files are called partial files. It is a convenient way to organize code. In care you want to use partial files. You will have to import them in app.scss file #import 'partials/variables'. Though you have to be careful about the order you import the partial files, in case you are using variables and mixins as they need to be imported first before other partials.
For more information checkout the sass documentation or this treehouse video
First case: i've got some script, which i've writed by myself(lets call it requests.js).
Second case: there is a big plugin TinyMCE, which i can install from bower or npm.
In first case as far as i understand, i should save my scripts in resources/assets/js. But where should i call them after this? There are 2 files in assets/js, which were installed with Laravel 5.3: app.js and bootstrap.js. Should i call my scripts in these files and then gulp them into a single one?
In second case i should use some npm or bower package manager. But, what should i do next? Where should i call this installed packages?In assets/js/ - app.js or bootstrap.js? But how, or maybe i shouldn't do it?
It's hard to put bower components in resource/assets/js only, because these components often consist of many files, js/css/others. I just use bower install inside root of the installation, bower_components dir appears and I put it into .gitignore. Anyone who pulls changes, can do bower install.
Going further, I make file, where I create json object with two values, js and css, where I put path to files I need. Then I require it inside gulp.js and I can do whatever I want with these files. Usually concat, minify, copy result to public.
Theres nothing wrong with putting frontend into same server. Maybe you work alone or in the small team, and you don't have time to manage too many things. Common practice I see all around is that people make dir angular inside root and just grab all js/html files inside this dir, and copy them to public inside gulp.
It's opinion based, but I think it is not a good practice to mix front-end and back-end.
Your Proposal
Your public (front-end) files, like bootstrap, you should store them in public/ of the Laravel installation. You can use public/assets/js, etc. The folder resources is not available in your html files (if you mean the folder of your Laravel installation).
Better Approach
A better approach is to separate totally your front-end from back-end. In that case, you need a front-end framework, like AngularJS or Ember.
Why?
You can replace one of them without troubles in the other
You can use your back-end as third party api (https://api.yourdomein.com/v1/...)
No conflicts with blade views and other template formats
Of course, separation of responsibilities
You should install your bower components in your resources/assets/js folder. Then add any of these components to your build process in your gulpfile. This way, you have total control over what gets concatenated and minified and ultimately included in your templates.
Hello I would like to create a simple PHP CLI to do some scaffolding. For a new project I am working on, we are using Magento to build an eCommerce store. Magento to comes with many default modules, but you can also create your own and we will have to be creating many custom modules.
I would like to create a simple PHP CLI which can be run to generate a default file path/structure for a module. It would be passed in something like the module name and maybe even path of the application and then generate the template folders and files.
I am new to PHP development, so i think this will be a simple enough project and a good learning experience. However I am having trouble knowing where to start. The end goal would probably be to have it archived in a .phar file that can just be run on the command line.
Any suggestions on how I can get started with this?
Thanks for any help, it is much appreciated.
No reason you can't. PHP in the command line reads the $argv array from the command line.
Here's one of my CLI apps; perhaps it can be instructive: https://github.com/dalecosp/NixArchive/blob/master/archive
I am learning Laravel. With composer i included the mobile-detect-bundle in the installation (files are in the folders). When i use the code as stated in the docs on github
$mobileDetector = $this->get('mobile_detect.mobile_detector');
i get this error:
**ErrorException**
File does not exist at path mobile_detect.mobile_detector (View: ) (View: )
I use this in my blade view and i think i have to set the path of 'mobile_detect.mobile_detector' but i have no clue what it has to be. Maybe one can give me a push in the right direction?
The reason it's not working is because you are trying to use a Symfony 2 bundle inside Laravel right out of the box.
As the github page says:
Symfony2 bundle for detect mobile devices, manage mobile view and redirect to the mobile and tablet version.
Basically, the line that you are trying to run is the way that you use services inside Symfony. It will work if you are in a Symfony application, but not inside Laravel.
// Get the mobile_detect.mobile_detector
// service from Symfony's service container
$mobileDetector = $this->get('mobile_detect.mobile_detector');
Although there might be some way to make it work, I'd sugggest to search in packagist for a Laravel specific package, or a PHP generic one that provides the same functionality, to make your life easier.
I've made a search and found this one, which is based in Mobile Detect too:
https://github.com/jenssegers/Laravel-Agent