How to go to parent directory in laravel 5.5 - laravel-5

I have created a Laravel 5.5 project and have placed few files inside the app.Http.controller.Auth.myfolder.myfile.
myfile has extension myfile.blade.php
I am trying to route the file as shown below
web.php
Route::get('/Sign-Up', function () {
return view('app.Http.Controllers.Auth.publisher.register');
});
web.php is place in route folder and folder route and app are in same directory.
but this method is not working.

Related

How Change laravel public_path

I changed my laravel installation folder structure by moving all files and folders from the root directory to a new folder 'core'.
The goal is, to have only the folders in the root directory of the project
core
public
I have updated the index.php in public folder but I have the following problem:
when I die dump the paths, all are correct except the public path
dd(app_path()); // somepath\project\core\app
dd(storage_path()); // somepath\project\core\storage
dd(base_path()); // somepath\project\core
dd(public_path()); // somepath\project\core\public
I want to retain all other paths and change only the public path to somepath\project\public instead of somepath\project\core\public , how can I do this, online docs I've reference focus on changing public_html to public but I don't want to change the public_html, just to tell laravel that the public path is somepath\project\public
This particularly needful for me as I use the laravel storage for handling uploads.
Below is my folder structure
project
|-core
|- every other folders and files
|-public
|-every other asset files
You need to rewrite the base path in the app/Providers/AppServiceProvider.php like so:
public function boot()
{
$this->app->bind('path.public', function () {
return dirname(getcwd(), 1) . '/public';
});
}

Using public and resources folder as alias in laravel

I split a laravel project into 2 parts, backend and frontend, I created 2 repos on GitHub.
In the frontend repo, there are only 2 folders, public and resources folder.
So, when I pull the changes on frontend, I would like all files to replace in backend folder too.
------ backend folder
---- public folder -> I want to it be an alias
---- resources folder -> I want to it be an alias
----- frontend folder
---- public folder
---- resources folder
When I create an alias of the public and resources folder in frontend, laravel won't work.
If I create a symlink of those frontend folders, laravel works but index.php file doesn't work as it doesn't follow symlinked path
How can I get it working?
To change public folder directory go to root index.php
Under the $app = require_once __DIR__.'/../bootstrap/app.php'; add below line:
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
To change the resource of view folder directory go to config/view.php and change your desire path.
'paths' => [
realpath(base_path('resources/views'))
],

Defining routes in api.php and web.php with same name

I have a route in my api.php file
Route::get('category/{id}/subcategory','SubcategoryController#categoryFinder')->name('cat_to_sub.find');
This route worked fine until i added another route in the web.php file
Route::get('category/{id}/subcategory',function(){return view('subcategories');});
And then when i run php artisan route:list
The URI api/category/{id}/subcategory has no name and i referenced that name all over my files and its throwing all these errors saying route cat_to_sub.find not defined
But when i remove the route in the web.php file everything works.
So whats causing this errors and is there another way to do it?

Change public directory laravel

I want to change the public folder to public_html, the main problem is that some commands and functions not work because it still point to public.
I am trying to use the laravel+vue to develop a spa. i normally rename the public folder to public_html and that's all, but know it seems that i have to use the public_path helper and the console and these use the public folder too.
im using npm run dev as in the laravel docs, but it generate everything in the public folder, not in the public_html that i have renamed
so how can i tell the console and the public_path helper to do they magic in the public_html folder?
I am using Laravel 5.6, it is a fresh project, with just a controller and a view with a mix helper calling the js that i want link this <script src="{{ mix('js/app.js') }}"></script>.
May this can help you. You can override Laravel default helper methods. This code helped me at a time when I got same problem like you.
Simple I created one helper file and override public_html function something like this:
/**
* Get the path to the public folder.
*
* #param string $path
* #return string
*/
function public_path($path = '')
{
return base_path().'/public_html';
}
Let's say file name is AppHelper.php and located into app/Http folder.
To override helper from base you need to include your helper file(AppHelper.php) before Laravel does it's own autoload file.
So for the web you have to include your file into index.php like this:
require __DIR__.'/../app/Http/AppHelper.php';
require __DIR__.'/../vendor/autoload.php';
Remember your helper must be included before autoload file. and this code snippet for Command line or Artisan CLI:
require __DIR__.'/app/Http/AppHelper.php';
require __DIR__.'/vendor/autoload.php';
You have to write your artisan cli changes into artisan file which is on root.
In Laravel if you check helper function then each and every function wrapped with if condition like this function is not exist then declare it using function_exists()
In our case we already declare public_path function and included before Laravel autoload file so every request first execute our function.
Hope this can help you. Good luck.
Add this in register() method of your AppServiceProvider
public function register()
{
// Add this part
$this->app->bind('path.public', function() {
return base_path().'/public_html';
});
}
For the css+js resources, as #Bagus Tesa said, you have a file named webpack.mix.js in the root of your application folder. It's not you who created it, it comes with the laravel project. In that file you'll find something like:
mix.js('resources/assets/js/app.js', 'public/js')
.sass('resources/assets/sass/app.scss', 'public/css');
Change the destination path from public to public_html

How to use SimplePie with Laravel

I am using Laravel 5.2. I need to get RSS feeds using SimplePie, so I install the library through composer.json and now my vendor folder contains simplepie but when i run the following code this error shows:
ErrorException in SimplePie.php line 1379: ./cache is not writeable.
Make sure you've set the correct relative or absolute path, and that
the location is server-writable.
My code in route:
Route::get('feed', function () {
$feed = new SimplePie();
$feed->set_feed_url(array(
'http://www.thenews.com.pk/rss/2/16' //it has no images
));
$feed->init();
$itemCount=$feed->get_item_quantity();
return $itemCount;
});
Create a writeable cache folder for simplepie in the /storage/ folder (I called mine simplepie_cache).
Set the path in your feed object:
$feed->set_cache_location(storage_path() . '/simplepie_cache');
That should do the trick.
check what is saying ./cache is not writeable can't write to cache folder check permissions to this folder or try a L5 wrapper for SimplePie https://github.com/willvincent/feeds

Resources