I am a beginner in laravel and have made one frontend page as blade.php
But not getting how to see the output on browser.
Is there any other code which I have to add.
If your blade file has name resources/views/index.blade.php, you need to add this code to file routes/web.php:
Route::get('/', function () {
return view('index');
});
Related
I want to redirect my page from pure php file to laravel file.
Is there any way to do so?
index.php
< a href="(laravel_file_here) " >Welcome </a>
In public folder suppose you have static_website.php -
<a href='/login'>Go to Login Page</a>
In Laravel routes file located at routes/web.php you can add
Route::get('/login', function () {
return view('login'); // located in resources/views
})->name('login');
This will take you to login page if you click on Go to Login Page in static_website.php page
I'm basically using VueRouter to create all my routes which is working really well. However, my application is built using Laravel. So if I refresh any of the routes I get an error that the route is not defined. So at the minute in every controller I've had to add an index function. This just returns the view of my app.blade which is just the usual tags etc and the to load my single page app. I'm just wondering if there is a cleaner solution? I guess I could move the return view into a single Controller and make my Controllers extend this. But I'm just wondering if there is a better way I'm missing?
i.e. one of my routes via VueRouter:
{
path: "/clients",
name: "clients",
component: () => import(/* webpackChunkName: "clients" */ "../resources/js/components/Views/Clients/Clients.vue")
},
The route in my clients.php file
Route::get('/clients', [App\Http\Controllers\ClientController::class, 'index'])->name('clients');
Then the ClientController index function
public function index()
{
return view('app');
}
It would just be nice to have the loading of the app.blade done somewhere else and not need to be specified per controller. Any help would be appreciated to ensure it's all done efficiently!
Thanks!
Here is how I solved this issue for one of my projects which is also single page application in Vue and Laravel: https://github.com/lyyka/laravel-vue-blog-spa/blob/master/routes/web.php
Simply, in your routes file, you put this code:
Route::get('/{any}', function () {
return view('welcome');
})->where("any", ".*");
And in my welcome view I have:
#extends('layouts.app')
#section('content')
<div class = "container">
<router-view></router-view>
</div>
#endsection
Basically this will return your app view for any URL and so your Vue SPA should work properly. Generally, it is not a good practice to put callback functions inside your routes file, but in this case, you won't even be using your routes file as it is a SPA, so this solution can pass! :)
You should use your single html file and make a controller.
On your controller
public function index(){
return view('index');
}
on your web.php
basically, you should make the same route on your laravel and vue
Route::get('/products', [ProductsController::class,'index']);
in my vue-routes
import Products from './components/Products.vue'
{
path:'/products'
component: Products
}
I just prepared this nice shopping website code
https://github.com/drehimself/laravel-ecommerce-example
I go admin page then upload some new items but
those item data and images are not dislayed.
I tryed to look contoller page but I couldn't find where are at.
Here is the web.php file
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
});
Could somebody teach me where should I change?
You can view all routes from
vendor\TCG\Voyager\routes\voyager.php
If you want to override any route then update in web.php
I am trying to manipulate the bread templates of the laravel voyager package. I have to put some new buttons to the templates.
i ve set up a route for the new admin page:
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
Route::get('order-payment-txns', 'AdminController#orderList')->middleware('admin.user');
});
//Controller
public function orderList(){
return view('vendor/tcg/browse-order')
->with("alert", "error.voucher_code_wrong");
}
How could it work with the right dataset?
You are doing so wrong.
copy the original browse, edit-add pages. After that paste to the
Resources\Views\Vendor\Voyager\BREAD NAME
If you dont have voyager folder just create.
"BREAD NAME" section is which page you want to edit. if you want to edit admin\news
Create Resources\Views\Vendor\Voyager\News\browse.blade.php
paste original browse codes in here. Edit it.
I may be being thick but I am continually getting a page notfoundexception .
In a view I have the following:
<a href="{{ route('/galleryimages/{id}') }}"
This part is OK. In web.php I have:
Route::get('/galleryimages/{{id}}', function($id){
return view('gallery_pictures.pictures',['id'=>$id]);
});
The page pictures definitely exists in the subdirectory gallery_pictures.
Your route is incorrect, Laravel route parameters use one curly braces, like so: {id}. Rather than {{id}}
The helper function you are using accepts route names not route URL's, to link routes you should use the url() function
https://laravel.com/docs/5.3/helpers
https://laravel.com/docs/5.3/routing
I've provided you some for reference links if you haven't already checked them out.
HTML Fix:
My Link
Route Fix:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
});
A little extra
If you want to use the route function you must set a name for your route, you can do it as so:
Route::get('/galleryimages/{id}', function($id) {
return view('gallery_pictures.pictures', ['id'=> $id]);
})->name('gallery_images');
Then you may access the route by doing something like so
My Link