Laravel view product page not found - laravel

I have a problem, doing some product page, already got listen all products from database. And now doing view object page, to check currently product details. Doing everything by this video:
'https://www.youtube.com/watch?v=SpOaqDJ2D3A'
But it's not working for me. Writing page not found when I press to a link View product.
1. I have created: view_object.blade.php
2. Have a controller:
'public function view_brac( $BrackID )
{
return view('view_object');
}'
3. Have a route:
'Route::get('view_object&(BrackID?)','BracController#view_brac');'
4. And this is a link to View full object:
'< a href="view_object& < ?php echo $ users->BrackID? >">Plačiau< /a >'
Can some you help, why this not working?

If you want to use URI with parameter like view_object?brackId=5, change the route to:
Route::get('view_object', 'BracController#view_brac');
The controller method to:
public function view_brac()
{
return view('view_object');
}
And the link to the view:
Plačiau
Then you'll be able to get the brackId in a view or a controller method with:
{{ request('brackId') }}

First, you aren't returning anything in your controller method along with the view.
public function view_brack( $BrackID )
{
$brack = Brack::find($BrackID);
return view('view_object', compact('brack'));
}
Second, the route definition is incorrect.
Route::get('brack/{brack}','BracController#view_brack')->name('brack.show');
Last, create your anchor tag using Laravel's helper functions.
Plačiau

Related

how can i make 4 links to a controller?

i'm setting up a new project in my laravel
The stuffs i have :
1- PostsController
2- Post model
3- Routes:resource('posts','PostsController')
4- after i login i have a create button for post create
after click on it i have below image :
My desire:
i want without changing whole project or whole routes resources have these :
after i login i want to have 4 boxes like this( i made it )
with this property :
after i click any of them i can create post according to their type
for example if i click on video content i enter to a page with 2 form:
like title video and upload video
after i click on text content i enter to page like the image i showed
you at the first
it means if i click on video content, resource route take me to create method in postscontroller and create method check if i came from content video link
return view (posts.create_video) or if i came from sound content link box return view(posts.content_sound) and etc boxes
how can i do all of that please help me thanks
You could structure it as following:
[routes/web.php]
Route::get('posts/create/{type}', 'PostController#create')->name('posts.create');
Route::resource('posts', 'PostController')->except(['create']);
[PostController]
class PostController extends Controller
{
public function create($type)
{
if (in_array($type, ['sound', 'video', 'image', 'text'])) {
return view("posts.content_{$type}");
}
abort(404);
}
}

Remove controller's name from url. Codeigniter

can someone help me with this. I want to remove controller name from the url like this
www.site-name.com/controller_name/controller_functions/controller_arguments
to this
www.site-name.com/controller_arguments
for instance:
www.site-name.com/blog/display/blog-title
to this:
www.site-name.com/blog-title
Below is my controller class
class Blog extends CI_Controller {
public function index() {
$data['blogs_data'] = $this->Blog_model->get_blogs();
$data['main_view'] = "blog/blog_layout";
$this->load->view('layouts/main', $data);
}
public function blog_display($page_url) {
$data['blog_data'] = $this->Blog_model->get_blog($page_url);
$data['main_view'] = "blog/blog_detail_layout";
$this->load->view('layouts/main', $data);
}
}
as your can see from my controller the URL of my site to display blog going to be like this www.website-name.com/blog/blog_display/($page_url) <== whatever the $page_url going to be. Now, what I want is to be like this www.website-name.com/($page_url) <= so straight to the $page_url.
Thanks
Go to application->config->routes.php
Then you can set a route to "blog/display/blog-title" as "blog-title"
Add the below line to your routes.php file
$route['blog-title'] = 'blog/display/blog-title';
You can replace "blog/display/blog-title" to "blog-title" then.
define route in routes.php file.
route['controller_arguments']='controller_name/controller_functions';
on which onclick you are showing this url.define there this.
<a href="<?php echo base_url(); ?>controller_arguments">
</a>
I imagine that your slugs are generated so you can't just write all your slugs into your routes.
In you specific case you need something like this in your routes:
$route['(:any)] = 'blog/display/$1';
Do bare in mind that your routes are used from top to bottom. So if you have this route as your first one the rest of your site might not work.
So in case of a entire blog stucture you might want something like:
$route[''] = 'blog/index'; // For first page without pagination
$route['(:num)] = 'blog/index/$1'; // Blog article pagination (for second page and all other pages)
$route['(:any)] = 'blog/display/$1'; // Blog article detail
To avoid some problems in the future with having a route that is just a (:any) param, you might want to add an extra segment in that blog detail article.
Like so:
$route['detail/(:any)] = 'blog/display/$1'; // Blog article detail
For more information about this subject take a quick look at the docs here: Codeigniter routing system

while page yet, i have set everything

I am trying to make via hi in view but its give me white page display. I have created controller and view ... path is also set in web.php
ROUTE:
Route::post('/member/add-single-trade/import_single_trades_parse', 'trades\ImportSingleTradesController#tradesImport');
CONTROLLER:
public function tradesImport()
{
return view('member.add-single-trade.import-excel.import_fields', compact( ''));
}
BLADE: import_fields.blade.php
hi
why dont you just return 'hi' in tradesImport() to see whether the route works fine
SOLVED: underscore does not work in route: /member/add-single-trade/import_single_trades_parse
It's working with : /member/add-single-trade/import-single-trades-parse

How to call data and view it on the footer?

This is the function that I am using in my controller
public function homeList()
{
//Get all the franchises
$franchises = Franchise::all();
//Load the view and pass the franchises
return View::make('frontend.layouts.footer')->with('franchises', $franchises);
}
and I keep getting this error. I don't know how to pass it or what to put on the routes.php file
You should be able to do #include('frontend.layouts.footer')->with('franchises', Franchise::all()).
Update:
To avoid the model in the view, you should use a view composer, as it was stated in a previous answer.
View::composer('frontend.layouts.footer', function($view)
{
$view->with('franchises', Franchise::all());
});
Now you have $franchises available in the view. This code you can place in routes.php or you can create a composers.php and autoload it.

JToolbar::save() redirection

I'm going through the Joomla 2.5 tutorial to build a custom component. Now I'm facing an issue on the redirection after using JToolbar::save() or JToolBarHelper::cancel for that matter. By default Joomla wants to redirect to the default layout (from the edit layout). However I don't want it to do that. I want it to redirect back to another view. In Joomla 1.5 I would have done this through adding the function into the controller - something like
function cancel()
{
//redirects user back to blog homepage with Cancellation Message
$msg = JText::_( 'COM_BLOG_POST_CANCELLED' );
$this->setRedirect( 'index.php?option=com_jjblog&view=jjblog', $msg );
}
Now that works beautifully for the cancel function, however for save this is a much more complex thing. If I want to overwrite the url do I have to redirect the controller to the model and then write in all the code for the model interaction? Because that seems slightly excessive just for a url redirection like you would in Joomla 1.5?
Hope you have added the save toolbar code with the proper controller name like this
JToolBarHelper::save('controllerName.save');
Create a save function in appropriate controller.
Add the task in the form
Finnally make sure you have added form action withthe corresponding component name.
You can try this-
In the controller firstly you call the parent save function than redirect to url.
function save(){
parent::save();
$this->setredirect('index.php?option=com_mycomponent');
}
OK it didn't need to $this->setRedirect at all. Just needed me to change the value to
protected $view_list = 'jjBlog';
which then sets the redirects of everything back to that list view.
Source link for this is here.
Thanks for all the responses though!!
view.html.php
protected function addToolbar ()
{
JRequest::setVar ('hidemainmenu', false);
JToolBarHelper::title (JText::_ ('Configuration'), 'configuration.gif');
JToolBarHelper::save($task = 'save', $alt = 'JTOOLBAR_SAVE');
}
controller.php
public function save()
{
$mainframe = JFactory::getApplication();
$mainframe->enqueueMessage (JText::_ ('COM_SOCIALLOGIN_SETTING_SAVED'));
$this->setRedirect (JRoute::_ ('index.php', false));
}
I think you can use
global $mainframe;
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
If you are overriding joomla's default save function in your custom component like
function save( $task = 'CustomSave', $alt = 'Save' ) // or even same name Save
Inside your controller you can use the CustomSave as the task and use $mainframe for redirect.
or
$mainframe = &JFactory::getApplication();
$mainframe->redirect("index.php?option=com_user&task=activate&activation=".$activation);
Hope this may help you..

Resources