how can i make 4 links to a controller? - laravel

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);
}
}

Related

laravel-livewire return view on button click

I have one button in livewire view
<x-jet-button wire:click.prevent="confirmProcess" class="bg-blue-500 hover:bg-blue-700">
Next
</x-jet-button>
and here in controller my method
public function confirmProcess()
{
return view('livewire.confirm');
}
I also have view in livewire folder with name confirm.blade.php
I want to load different view on button click but when I click on button nothing happens.
how can I load other view also I want to use data from same controller also on other view.
Thanks
You can't return view from your confirmProcess method. What you can do is redirect from confirmProcess method to a named route like:
return redirect()->route('confirm');
Then from this route you can call the component like:
Route::get('/confirm-process', \App\Http\Livewire\Confirm::class)->name('confirm');

Laravel - Authorize with other policy

I have a gallery policy and a photo policy, a gallery controller, and a photo controller.
It works like this:
user-> hasMany galleries -> hasMany photos
I do have a photo upload page (with dropzone), that uses the photo controller.
the url is like this: /gallery/3/upload
I want to restrict access to this page only if the user is the owner of the gallery 3. But this page uses the PhotoPolicy, that makes use of the Photo model, not the Gallery model.
How can I authorize this page, using the GalleryPolicy instead of the PhotoPolicy? Or do I have to copy over the view method from the GalleryPolicy and have it also in the PhotoPolicy?
EDIT:
I do not understand this...
In my PhotoPolicy:
public function view(User $user, Photo $photo)
{
return false;
}
In my Photos controller:
$this->authorize('view', $photo);
In my AuthenticationServiceProvider:
protected $policies = [
\App\Gallery::class => \App\Policies\GalleryPolicy::class,
\App\Photo::class => \App\Policies\PhotoPolicy::class,
];
Restult: page loads just fine.. even if return is false.. why?
You can authorize this page in PhotoPolicy in create method, because you have just one way to upload images which is also using this url.
In PhotoPolicy you have gallery's id which it was passed as params, so you can check owner of gallery and restrict them.
And another point is according to API rules it's better change upload's url to gallery/3/photos.

Laravel view product page not found

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

Joomla MVC Module delete model

I'm a newbie on Joomla developing and I'm trying to fix an old administration module made by 'someone before me'. Module's been developed using MVC Components, it has several CRUDs and I'm stucked at deleting an item. The template view adds the toolbar icon like this:
JToolbarHelper::deleteList('', 'paises.delete', JTOOLBAR_DELETE);
It also has at the list controller (DistribuidoresControllerPaises), the getModel function:
public function getModel($name = 'Pais', $prefix = 'DistribuidoresModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
The model class:
class DistribuidoresModelPais extends JModelAdmin
When selecting an item on the list, and clicking the trash button an empty page opens with this ending:
administrator/index.php?option=com_distribuidores&view=pais
If I come back to grid, the item still remains.
Any suggestion?
Thanks in advance
You can debug this by enabling debugging from Joomla configuration or you can try to to check with exit with in "delete" function of "paises" controller and can check you get item ids in post request or not.
Also you are using view "pais" also using model "pais" then why you are using "paises" controller for delete function, you should use "pais" controller to delete.
Also provide delete function which you are using to delete items, it may contain some issue.

Passing parameter to same page with CodeIgniter

I have a controller that loads a page view. The page is actually a template of sorts; when a user clicks a button, content is loaded into a div based on the parameters passed through the button link. All button URLs go to the same page, it just passes a parameter. So for example, I have a page controller and a page_view file. When I click on the login button I want to go to the same page, but just pass action="login". If I clicked on "see stats", then I would want to pass action="stats".
Without Codeigniter I know I can just set the URLs on the buttons to "?action=stats" or "thisurl?action=stats", and within the page itself I have code that checks to see what the value of action is, and then generated content based on value.
How can I do this with the CodeIgniter framework?
You can call methods on a controller. So if you call a page like /your_controller/login, then it will call the login method in the controller and you can change the view to match that:
class Main extends CI_Controller {
function Main(){
parent::__construct();
// called when /main is accessed
// load your main view here
}
function login(){
// called when /main/login is accessed
// tweak view to match login view
}
}
More info here: http://codeigniter.com/user_guide/general/urls.html

Resources