add links for blade php pages - php

I have developed several pages for my applications. Now I need to add link for these pages. Till now I was opening these pages via url browsing.
My web.php page
// for books
Route::get('/book','BookController#create');
Route::post('/book','BookController#store');
Route::get('/book/{id}','BookController#edit');
Route::patch('/book/{id}', 'BookController#update');
// for ordered books
Route::get('/order','OrderedBookController#create');
Route::post('/order','OrderedBookController#store');
Route::get('/billSearch','OrderedBookController#searchBill');
Route::post('/billSearch','OrderedBookController#billPay');
Route::post('/billSearch/{id}', 'OrderedBookController#pay');
// for Books Out
Route::get('/booksout','BooksOutController#create');
Route::post('/booksout','BooksOutController#store');
List of pages corresponding to the routes
book.blade.php
edit.blade.php
booksin.blade.php
booksout.blade.php
local host url to browse these pages are ::
http://127.0.0.1:8000/book
http://127.0.0.1:8000/order
http://127.0.0.1:8000/billSearch // for Route::get('/billSearch','OrderedBookController#searchBill');
http://127.0.0.1:8000/booksout
How can I create link in my web apps since I am browsing my pages via routes, not by pages ?

Use route() or url() functions.
e.g. in blade view:
More in laravel docs

You may links different pages in laravel by using one of the two ways
1: By including url which you define in your route in the blade href
Route::post('/billSearch', 'OrderedBookController#pay');
therefore in your blade link
2:By using the name of the route
Route::post('/billSearch', 'OrderedBookController#pay')->name('bill);
Therefore in your blade view

just insert your routes like this:
Book --> http://127.0.0.1:8000/book
Bill Search --> http://127.0.0.1:8000/billSearch

Related

How can I move the login behaviour from the /login URL to my home page in a Laravel application?

I am pretty new in PHP and moreover in Laravel framework (I came from Java) and I have the following problem related to Laravel security.
I have correctly configured my Laravel login system so if I access to the page:
http://localhost:8000/login
I obtain my login page from where I can access to the restriced area of my portal. This is the standard Laravel login page.
My doubt is: can I take this behavior into my home page? Because I have to put the login into a custom login from into my home page (the one that is automatically opened launching http://localhost:8000/).
How can I do this?
From your question i understand that:
You are adding the login form in the homepage and not trying to provide the link to the login page from homepage.
If this is not your question i could delete my answer.
So, if you are using blade you could easily import the chunks of codes from login page.
More on Sub-view Here:
https://laravel.com/docs/5.3/blade#including-sub-views
Example:
login.blade.php
<div class="form">
//your login form contents
</div>
homepage.blade.php
//your homepage codes
#include('login')
//rest of your homepage codes
Note:
The path to your subview is relative to resources/views/.
i.e. If you have this folder structure like this:
|-resources
|-views
|-homepage.blade.php
|-partials
|-login.blade.php
then you will need to use:
#include('partials.login')
in your homepage.blade.php to use that view.
Inside web.php add this route at the end of the routes
Route::get('/', 'Auth\AuthController#getLogin');
You can update routes file in laravel like below.
Basically your routes file is located in
YourProject/app/Http/routes.php
here you can copy the View(blade) / Controller of /login route to /. Like example shown below.
Route::get('/login',function() {
return view('login');
});
Replace the above one to
Route::get('/',function() {
return view('login');
});
example above is without controller.
Hope it works!!

Dynamic views with Codeigniter or templates or partial views

How can I load views of my nav menu without reloading the entire main view? something like templates or partial views. Is necesary to do this with ajax? How can it be? I donĀ“t know much about ajax. It will be possible to see an example?
I load my home view in controller like this:
$data = [
'header_view' => 'main/header',
'nav_view' => 'main/nav',
'section_view' => 'main/main_view',
'article_view' => 'main/article',
'aside_view' => 'main/aside',
'footer_view' => 'main/footer',
];
$this->load->view('home_view', $data);
Then I load the vievs from home view:
<section>
<?=$this->load->view($section_view);?>
</section>
...
And in the nav view I wanted to put the links to different sections without reload the nav view, because I will have a tree structure and other stuff.
why don't you use AngularJS ? you can make a single page application using ui-routes or ng-routes. you can make ajax call to your controller method that will render your view, and you can show that view in .
EDIT
In order to do a one page iframe site, you need to set up a controller to return a page without anything else
Controller -> loadpage($name)
then route it however you'd like
then, create an iframe with an id
<iframe name="maincontent"></iframe>
obviously, add in your needed styling / attributes.
On your links, add in targets
Link 1

How to call one controller(function) view with multiple url in codeigniter via routes.

I create a controller function home/index .
calling vai url it is showing me html design.
I want to call the view of home/index via custom urls.
If I type
www.example.com/home_new // it will open view of home/index
www.example.com/home_new1 // it will open view of home/index
Also i want to save the custum urls in database so that admin can change.
Please advise how to do this via routes or another method.
Add this code to inside route.php file:
$route['home_new'] = 'home/index';
$route['home_new1'] = 'home/index';
This will solve your problem. For database it will not help you.
You can take reference from this link.

Different urls generated with JRoute::_() in different pages - Joomla! 3

I developed a component in Joomla! 3, and I used JRoute::_() & router.php to make urls search-engine-friendly. something like this :
/component/products/WIFI-IP-Phone/list-3
So I decided to replace /component/products with a clean alias, And I created a menu with a clean alias to the component home page. now, all the link I have inside the component ( generated with JRoute::_() ) are like this : /escene/WIFI-IP-Phone/list-3 and its perfect, its exactly what I want, But ... I'm using JRoute::_() in three different modules, and I generate links with that, the problem is that generated links in these modules when I'm in the home page or any other page except the component pages, are different with the generated links in these module when I'm in the component pages.
When I'm in the home page or other : /component/products/WIFI-IP-Phone/list-3
When I'm in my component pages : /escene/WIFI-IP-Phone/list-3
Any body can explain the reason Or help me to make all urls like /escene/WIFI-IP-Phone/list-3 ??
This is because the functions you write in components router.php get executed for the links when the page displaying is of the same component. But there is a way to accomplish this task.
1. First create a new menu in the menu manager and create all links in this menu.
2. Publish this menu but do not assign any position.
3. In this way you would get a sef url for each link.
if(JFactory::getConfig()->get('sef')) {
echo 'My sef url';
} else {
echo 'Dynamic url';
}
In this way Joomla will do your url parsing by detecting your component through the alias stored.
Let me know if you have any further query.

CodeIgniter - creating forms with .html link

I want to create a simple website with 5 pages which contains 2 simple contact us forms.
The links should be www.yoursite.com/contact.html and after submitting it should go to www.yoursite.com/success.html. Please help, I have searched a lot for it but couldn't find anything
[edit]
I have a different controllers for different forms but in the links i don't want the controller name but only the view name.html
If all you want to do is change the apperance of the URLs, then you could use CodeIgniter's routing. You'll most likely also want to remove index.php from the URL, more information is available in CodeIgniter's user guide.
For example, if you have a controller named Contact with an index() function that loads the view for the contact form, and another function success() that loads the success page view:
Then this route, in application/config/routes.php would map the URL, www.yoursite.com/contact.html to your Contact controller.
$route['contact.html'] = "contact";
This route would map www.yoursite.com/success.html to the success() function within the Contact controller.
$route['success.html'] = "contact/success";
If you want your Codeigniter URLs to have ".html" appended to them for some reason, you should modify your application\config\config.php file and change
$config['url_suffix'] = '';
to
$config['url_suffix'] = '.html';
You can see here for more info.

Categories