how to make working menu tab with laravel 5.4 - php

I am working on Laravel 5.4
I have created a menu, in which three tabs Home, about and contact. When I click on Home then it should be on home page. When click on about, it should be on about page....
web.php:
<?php
Route::get('/', function()
{
return View('method1.home');
});
Route::get('about', function()
{
return View('method1.about');
});
**method1 is folder in resources\views**
home.blade.php:
#extends('method1.dashboard')
#section('content')
<h1>This is home page</h1>
#endsection
about.blade.php is:
#extends('method1.dashboard')
#section('content')
<h1>This is about page</h1>
#endsection
dashboard.blade.php is:
#include('method1.includes.menu-header')
menu-header.blade.php is:
<li class="active"> Home</li>
<li> About</li>
But when I click on home or about page. It shows Page is not found.
My laravel projet folder name is admin_laravel. When I run http://localhost/admin_laravel/ then it shows home page and when run http://localhost/admin_laravel/about it shows about page.
But when I click on about menu button then in browser shows link http://localhost/about. Means it is not going with http://localhost/admin_laravel/about and page is not showing.

You are missing something there, For a quick fix you can do this:
<li class="active"> Home</li>
<li> About</li>
You can also give route name and go with route method:
Route::get('about', function()
{
return View('method1.about');
})->name('about');
Then:
<li> About</li>
Here is the details: https://laravel.com/docs/5.2/helpers#method-route

You're hard-coding your URLs. When you have <li>About</li> you're telling your browser to go to the about path from the root of the domain (which is what happens when you prefix your URL with /), which in this case is http://localhost/.
There's a few things you should be doing. First, set the base URL for your project, you can update APP_URL in your .env file
APP_URL=http://localhost/admin_laravel
or the url option in config/app.php.
'url' => env('APP_URL', 'http://localhost/admin_laravel'),
Secondly, when generating URLs in Laravel there are quite a few options. If you're not using named routes, then you should use the url helper method to generate your URLs:
<li>About</li>
That will make sure that your URL is based at the root of your project, rather than the root of the domain. When you use url in conjunction with the correct setting as described above, your URLs will be generated correctly.

Related

Why I am getting wrong URI?

I am currently on
http://127.0.0.1:8000/cars/
I have a link that has to route me to
http://127.0.0.1:8000/cars/create
I used this in my code
<a
href="cars/create"
</a>
In my web.php I have following route
Route::get('cars/create',function ()
{
return view('carsops.create');
});
When I click on link I am redirected to
http://127.0.0.1:8000/cars/cars/create
Instead of
http://127.0.0.1:8000/cars/create
What is the error why I am getting this extra /cars.
Can some one help me.
You have to put a / in front of the link:
<a
href="/cars/create"
</a>
This means Go to the site root, then got to cars path then go to the create path.
This is solution is not nice. Why? Ok, you should use route names in the your application.
How to solve this problem correctly?
A first step is set name to your route. Modify routes/web.php like to
Route::get('cars/create',function ()
{
return view('carsops.create');
})->name('carsops.create');
Look at the name. Name can be as you wish.
Step 2 is, calling your route in the blade like to
<a
href="{{ route('carsops.create') }}"
</a>
Well done.
Laravel a href links are made by giving name,
if you want a return view without variables you don't need to get a method
Route::view('cars/create','carsops.create')->name('yournamelink');
use in blade page
goto page
A root-relative URL starts allway with a / character, to look something like create car.
The link you posted: create car is linking to an folder located in a directory named create in the cars, the directory cars being in the same directory as the html page in which this link appears.
It is therefore easier to work with Laravel Helper. As already mentioned here.
<a href="{{ route('car.create') }}"</a>
You define the route names in your web.php and for api links in your api.php file.
Route::get('/create-car', [App\Http\Controllers\PageController::class, 'create'])->name('car.create');

How to solve the route changing to another when I make a scroll to the section of the same page in Laravel 8?

I am using blade template for laravel and I want to make a navigation link that scrolls to the section of the same route.
Here is the code example...
<li class="nav-item">
<a class="nav-link" href="#ask_for_help">Ask for Help</a>
</li>
<div id="ask_for_help">
The section that I want to reach.
</div>
It did reach to this section, but the route changes to
localhost:8000/#ask_for_help
instead of staying at the same route
localhost:8000

How nav bar works in this php code using codeIgniter?

This is a source code of nav bar made using PHP framework CodeIgniter.I didn't understand login behind nav url of "Bulk Conversion" and "Login" which is given using site_url instead of <a href = "bulk_conversion.php"> and <a href = "login.php">. How nav bar code works here?
<div class="header clearfix">
<nav>
<ul class="nav nav-pills pull-right">
<li role="presentation" class="{{ $_nav === 'batch' ? 'active' : '' }}">Bulk Conversion</li>
<li role="presentation">Login</li>
</ul>
</nav>
CodeIgniter is an object-oriented MVC framework. For the most part you don't make calls to .php files by name. Instead, CodeIgniter uses a segment-based approach to URLs with a one-to-one relationship between a URL string and its corresponding controller/method and optionally, parameters. Any URI segments after the first two are considered parameters (variables) passed to the controller's method. Find a better explanation of what I'm trying to explain in the Documentation.
site_url is a CodeIgniter helper function that will construct a full URL from a URI string. So the call to site_url('batch') for a website on example.com will produce the string http://example.com/batch. This will result in the index() method of the controller Batch being executed.
The call site_url('admin') works the same except the Admin controller is being called.
Clear as mud?

codeigniter's controller to main controller in a specific div

<li>SERVICES</li>
<li>ABOUT</li>
<li>CONTACT</li>
I'm using CodeIgniter and this code was in a different controller. suppose http://localhost/defctrl/function1
I want to return to my homepage "maine/home" in a specific div when you click on the list but the above code doesn't work. neither ../maine/home#services.
How can I solve this problem?
if it's on the same page you can use
<li><a href="#services"
if another page
<li><a href="<?php echo base_url() ?>{route or controller name}#services"
Make sure URL helper is loaded and site load with index.php

codeigniter linking to another page

i am new to codeigniter framework. i am having problem with href link. in my home page i have some menu, that goes to different page. for example in normal php if i want to go Sell Books page then i just put sellBook.php in href link. now in codeigniter how can i do this. do i need write something in controller ?
<li >Home </li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
as per MVC pattern each of your url is a controller so:
if you, for example, want to link to
http://www.site.com/users
so the controller will look like:
class Users extends CI_Controller{
function index(){
//do somenthing here
}
function list(){
//list your users
}
}
then in your views linking to that controller is simple:
this will link to your users controller and index() method
this will link to your users controller and list() method
the site_url(); method will helps you finding the right link both if
you are using index.php or not in your urls
<a href="<?php echo base_url() ?>controller_name/function_name">
If you are using mod_rewrite to remove the index.php from the URL, you can write your URL as href="/sellbook" otherwise you will have to include it, such as href="/index.php/sellbook".
This assumes, of course, that you have a properly configured route name sellbook. See http://ellislab.com/codeigniter/user-guide/general/routing.html for details on how to achieve this.
If the links are to other pages on your site, then I think your best bet will be to use the url helper, assuming you're using the standard seo friendly format and not query strings. This way, you don't have to take into consideration whether you'll be using .htaccess or not. For example:
echo anchor('your_controller_name/your_function_name/param_1/param_2', 'Sell Books', 'title="Sell Books"');
// or for your home page
echo anchor('/', 'Home', "title='Home'");
If it's an external link, you can use the same function or just a plain html tag:
echo anchor('http://google.com', 'Google Me', 'title="Google Me"');
// OR
<a href="http://google.com" title="Google Me" >Google Me</a>
Note: make sure you load your url_helper in your controller if you'll be using the anchor function:
$this->load->helper('url')
// or add to autoload.php
You can also do it the way #sbaaaang suggested.
Account Details
You can use like this
<li>Home</li>
<li>Buy Books </li>
<li>Sell Books </li>
<li>Books on Demand </li>
<li>Request a Book </li>
<li>About Us </li>
//use
site_url in link with controller name and method
and
$this->load->view('page_name');

Categories