Until a while ago I was using this lib (https://github.com/scottbedard/vuetober) to use vuejs with octobercms/wintercms, however, in the new versions of Node, NPM and Wepback this lib doesn't work anymore, because the variables that are used to give the "output" of the compiled files no longer exist..
Would anyone have a solution to use Vue 3 in which I can create the files in the themes/my-theme/assets folder in the vue build action and also have an index.htm file in the "pages" folder, something similar to the lib above do?
From what I understand the new version of webpack no longer has access to the "public" variable, that's why the vuetober lib stopped working.
// configure the dev server and public path based on environment
options.devServer = {
disableHostCheck: true,
public: 'http://localhost:8080',
};
options.publicPath = isProduction
? getProductionBaseUrl(api, pluginOptions)
: 'http://localhost:8080/';
Related
Laravel Project is installed in my root directory and I have another project inside root directory with Core PHP ,
COREPHP-PROJECT is the one I want to access , but every time I try to access example.com/COREPHP-PROJECT it's giving me 404 error.
I have tried more than 50 solutions from internet and nothing is working so far.
What I'm doing wrong here?
NOTE: .htaccess file is renamed as I wanted to test without it too.
I think it is actually fine to have a project directory inside the applications root directory. A good application should not be build inside the framework. It should be build with the framework. If in 5 years somehow laravel is not anymore supported you can decouple it more easy and use it in a new framework.
You just need to assign the path to your composer.json under the psr-4 part.
"autoload": {
"psr-4": {
"MainApplication\\": "app/",
"CorePhpProject\\": "CORE-PHP-PROJECT/app/",
But you should only route over the Laravel router.
You can add your routes inside laravels RouteServiceProvider.php
Have a look at the documentation:
https://laravel.com/docs/8.x/routing#the-default-route-files
Should look something like this then:
Route::prefix('coreproject')
->group(base_path('CORE-PHP-PROJECT/routes/web.php'));
Then you can call your laravel routes like this
/home
and the project one are called like /coreproject/home
I got into same task of integrating core php folder inside laravel , therefore solution i found that create a core php file with extension test.php in public folder at laravel root, and try to access in browser after php artisan serve, you will find you can access it.
I created a vue/cli 3 project and its in my documents/project folder. Im running it on port 3000 with "npm run serve" command. Now, i want to have a backend folder somewhere to serve PHP files. But i want both the frontend and backend to be in the same folder structure.
Currently, my vue is in my documents folder and my php is in my xampp folder. The problem im having with this is managing 2 folders and git for the same application. Also, this causes my ajax calls from my vue projet to use a silly url such a "http://localhost:80/project/file.php". Id like to use relative paths like "backend/clients/getClient.php" that would be somewhere within my vue project.
This is what i would like:
myProject
frontend
my vue stuff like public and src folders
backend
my php files
It doesnt have to be exactly that way but the point is that now i have a single folder and git for a single project.
thank you.
The way I do this is as follows:
1)
I put the php files in a subfolder the public/ folder in the vue/cli project structure.
That way, these files will get copied to the dist folder on building the project.
For example: I have the file /public/api/endpoint.php, this will end up in dist/api/endpoint.php.
For testing locally I now copy the php files to the xampp/htdocs dir whenever I change them. But I guess you could skip this step by setting up a xampp alias directory. (But I haven't tried this myself yet)
2)
The ajax urls still differ between local development mode and production. To solve this I define a webpack plugin in my vue.config.js:
const webpack = require('webpack')
const API_URL = {
production: JSON.stringify('https://www.project.com/api/endpoint.php'),
development: JSON.stringify('http://localhost/project/api/endpoint.php')
}
// check environment mode
const environment =
process.env.NODE_ENV === 'production' ? 'production' : 'development'
module.exports = {
...
configureWebpack: {
plugins: [
new webpack.DefinePlugin({
API_URL: API_URL[environment]
})
]
},
...
}
Then use this in a vue/js file like:
const apiUrl = API_URL // eslint-disable-line
(the eslint directive is only needed If you have linting turned on with eslint, it will throw an error that API_URL is not defined.)
Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.
Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.
Basically, I can't start the Angular application at all with this setup.
How can I overcome this?
In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.
I make API with Laravel and use it with Angular 2.
In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves.
I also use gulp to copy the built files from /dist to /public
I had the same problem and what I found is this related issue in their GitHub issues:
The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.
This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.
So, you can't really achieve what you exactly want, but this is the only workaround I found.
I found only one solution for me.
create build for client side code by ng build --prod
Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
Using gulp-ingect plugin inject copied files into layout gulp inject
-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>
-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).
P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.
Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there…
And add an appropriate route into Laravel routing. Like this one, for instance:
Route::any('{path?}', function () {
return File::get(public_path() . '/index.html');
})->where("path", ".+");
Btw, it’s simply a trap for any unknown routes… But I think you get an idea.
I am php developer use laravel-4 as framework for building web applications , in the last few days I wanted to create phar file from my web application created on laravel framework .
I searched in the web for tools build php archive files (.phar) and I found
PHP box , this tool is very good and use json configuration file for building the phar files but i could not use it for creating my phar files because there is many considerations when creating phar file from a web application use a framework like laravel . my questions are :
laravel use composer autoloader as auto loading mechanism
1- how to handle composer auto loading mechanism ?
2- how to handle the framework bootstrapping process ? 'like laravel'
3- what i need to make the browser read my index page from inside the phar file ?
4- how to use framework command line tools from the phar file ? 'like laravel-artisan'
You might use composer.json in your application and require box there.
When your application runs on laravel, you know that your bootstrap works and would also work inside a phar.
I believe Box brings a lot of the composer autloading stuff itself, so you won't run into trouble with it. I think the class_map gets included automatically.
One thing to consider is, that configuration details must be passed in!
In general, you need to "forward" to your application, which is inside the phar, like so:
<?php
require_once "phar://myapp.phar/frontcontroller.php"; // maybe index.php
$config = array('dsn' => 'database-config');
Application::run($config);
Also accessing a PHAR in a PHAR is a problem!
You can't access a PHAR packaged in a PHAR directly.
Firstly you need to extract the packaged PHAR, secondly do the forwarding call and pass the CLI commands along. Problem solved here: https://stackoverflow.com/a/13537329/1163786
Full Example
box.json.dist
{
"main": "bootstrap.php",
"output": "application.phar",
"compactors": ["Herrera\\Box\\Compactor\\Composer"],
"chmod": "0755",
"directories": ["src/"],
"stub": true
}
bootstrap.php
<?php
require 'vendor/autoload.php'; //<-- this is autoload.php generated by Composer
use MyApp\Application;
$config = parse_ini_file(__DIR__.'/config.ini');
$app = new Application();
$app->run($config);
I am trying to include the YouTube Analytics Service of Google but I can not access it through the Vendor folder.
include(app_path.'path/to/analytics/Google_YoutubeAnalyticsService.php')
It is not working, because it defaults to the App folder.
How can I get out of the App folder and into the Vendor folder (where the YouTube Analytics file is at)?
The error is {
include(C:\xampp\htdocs\mysite\app/path/to/analytics/Google_YoutubeAnalyticsService.php):
failed to open stream: No such file or directory
From where do you want to include that file ?
Place a reference to your file in composer.json autoload object:
"autoload": {
"files":["your_file_path"]
}
Run composer dumpautoload, and you'll have your file :)
Actually you have in the helpers function the path so basically the function base_path give the direction to the root of your project so
echo base_path() . '/vendor';
Should be the route to your vendor folder.
You can se all the documentation in
Helper Functions Laravel
Be sure that you are seeing the documentation of the laravel version that you are using (I put the link for the 4.2 version).
This question was asked a long time ago and the answers reflect that. Most the time now all you need to do is import it using the "use" statement if you installed it with composer. Composer will already reference all the important directories.
It should be something like this, but it will vary depending on the project.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\Class;
That could include a base class as well as some exception classes.
use FolderNameUsuallyGitHubUserName\ClassNameorGitHubProjectName\ClassException;
Usually most packages if compliant with modern composer and php standards work in this fashion.