Laravel 5 - static image assets broken when passing parameter in URL - php

When I pass a URL parameter (Laravel 5.4) I'm seeing the static images on my page not load (the usual broken place holder image instead) but without the URL parameter and using the exact same view, they load fine. So http://localhost/site/public/filmpage shows images but http://localhost/site/filmpage/batman doesn't show images (all other assets load fine). Wondering why this is, and how to fix it please?
I've got my web.php route file with:
Route::get('filmpage', 'FilmController#filmpagetest');
Route::get('filmpage/{name}', 'FilmController#filmpage');
then controller file with:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class FilmController extends Controller
{
public function filmpage($name)
{
return view('filmpage',array('name' => $name));
}
public function filmpagetest()
{
return view('filmpage',array('name' => 'hello'));
}
}
I'm running Laravel on my Win 7 64 bit machine, PHP 5.6.24, Bitnami WAMP Stack 7.1.2.
Thanks for any suggestions.

Using informations you provided I think your assets are linked like that:
/path/to/asset/file.ext
but you are loading images using paths like that:
path/to/image.ext
Note missing / and the beginning.
Thats is why your images may not be loaded.

Related

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

I try to display a view but I get a 404 not found error, but my code seems correct
this is the route created
Route::get('talk',[\App\Http\Controllers\TalkController::class,'index'])->name('talk.index');
the controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
class TalkController extends Controller
{
public function index(): view
{
return view('talk');
}
}
here is what I got as a result
enter image description here
need help please
I was Facing the Same Problem laravel Store cache and if you stop the serv and start it all over you will still see the 404 so its better to do :-
php artisan optimize
php artisan optimize creates a compiled file of commonly used classes in order to reduce the amount of files that must be loaded on each request. The file is saved to, or overwrites, bootstrap/cache/compiled. php , which needs to be writable by the web server (PHP process).

Laravel 5.4 remove public from url :Side effects

I have successfully removed 'public' from my Laravel project URL.
Now when I include any asset using helper function asset() I have to include public at all places like below.
asset('public/images/a.img')
When I try dumping helper function basepath() and publicpath(), correct values are displayed. How can I avoid writing public all the times in all calls to asset. Is there anyway asset function uses publicpath() instead of basepath().
You have to set your Web Directory on your Web Server to point to
/yourproject/public
it seems like your pointing now to
/yourproject/

Laravel unable to load view

Just started learning laravel I tried to create a route for my view but when I load on the web browser it says Sorry, the page you are looking for could not be found. Can any one help me out in codeigniter it was so simple just create a controller and view and we can see on the web broswer I found laravel to be difficult then codigniter is that true?? can anyone define me how is the mvc structure for laravel5 as i found tutorials but they are of old laravel and files and structure are almost change so I got confused any suggestions please
routes.php
Route::get('main', 'Main#index');
Main.php
namespace App\Http\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class main extends Contoller {
public function _construct() {
$this->middleware('guest');
}
public function index() {
return "Hello World from controller";
}
}
if you are running laravel project locally, it can run through its own server. you dont need apache server form wamp or xampp,,but you will need their mysql database. So start only that if you require database.
Now go to command prompt, navigate to the directory where your project is stored eg cd c:/wamp/www/yourprojet and then type following command
php artisan serve
it will start on port 8000 by default. and you can now access your project at 'http://localhost:8000/'
and you can access your view at 'http://localhost:8000/main'
Also you can find laravel tutorials and other at laracast
Try to change the class name to Main (now is main, in lowecase)
I learnt Laravel by their awesome tutorial: https://laravel.com/docs/4.2/quick
make a view in resources->views, something like my-view.blade.php
Then return view('my-view');
That my-view.blade.php can have whatever HTML you want in it
Go to your resources/views folder create file with filename.blade.php.
Now in your routes.php:
Route::get('main', 'Main#index');
And in your controller add this function:
public function index() {
return view('filename');
}

Laravel possible to route to a single php file?

I have am using Laravel and I am trying to call a single php file via the browser, which is
located in my app path.
I have setup a Route::get to a function HomeController#index
function index(){
include(app_path().'/myphpfile.php');
}
And gets called when doing http://localhost:8888/home/index
This is how I call it atm.
The Problem is my file accepts furthe parameters, which are
processed inside my php file like:
http://localhost:8888/myphpfile.php/user/hello1
or
http://localhost:8888/myphpfile.php/user/hello1/default
So I tried to use Route::any.
It is not working. Can I somehow just tell Laravel to pick up the php file like I mentioned above? Other way then using include?
I donĀ“t want to put this file into the public folder.
Something like wildcard routing.
Thank you for your help.

Laravel not getting resource?

I am a noob with laravel just picked it up today, what seems to be an easy task that looks lovable has caused a headache.
I am following a tutorial from Jeffery Way, and we seeded the database, the next step is to create a controller and get the resource. I generated the necessary files, then followed these basic steps.
The database table is 'players'
Step 1.
//Here is the index() function inside my PlayersController.php
class PlayersController extends \BaseController {
public function index()
{
return Player::all();
}
}
Step 2.
//Inside the app/models/ directory I create a file called Player.php
//Here is the code inside Player.php
class Player extends Eloquent {
protected $table = 'players' // I tried without the protect aswell
}
Step 3.
//Finially a route
Route::resource('players', 'PlayersController');
Route::get('/', function()
{
return View::make('hello');
});
For extra measure I also ran composer dump-autoload in the command line, inside the root directory of my laravel project.
Then now I wasnt told which directory the route would be in, since it's an index function I assumed it's inside the root, so I have tried several url's
http://localhost/basketball-app-framework/public/players
http://localhost/basketball-app-framework/players
This last one would obviously only work if I pointed localhost to the public directory, I did do that however, still a no go. I am confused as ever.
http://localhost/players
I have tried a bunch other url's but those only are the ones that make sense, and the ones I am pretty sure should be working.
It blows I have to do some digging to figure out this simple mistake I am sure I am making, but whatever it takes to understand why I cant fetch that data from my database.
Okay looks like it was a mod_rewrite, and AllowOverride All issue inside the http.conf file.
I figured out some better keywords that applied to my issued and came across this Laravel 4 simple route not working using mod_rewrite, and .htaccess
As of now the simple users route that the documentation provides works. http://localhost/basketball-app-framework/public/users returns Users!.
So its nice to have this figured out, I still feel confused though haha.

Categories