i am trying to delete some livewire blade and component with
php artisan livewire:delete showcase
and then in the routing(web.php) i connect it with the one in the controller (ShowcaseController), but when i load the page, its still asking the blade from livewire (Showcase.blade.php) instead the blade that i made outside livewire folder (the one that has been deleted).
does anyone know how to solve this or remove livewire blade and component that has been made safely? im using laravel 8 and livewire 2
thank you
showcase routing code
//------------------Controller Showcase------------------//
use App\Http\Controllers\ShowcaseController;
Route::get('/showcase', [ShowcaseController::class, 'index'])->name("showcase");
showcase controller code
public function index()
{
$products = Product::all();
return view('Showcase.showcase', [
'products' => $products,
]);
}
all done guys i just put the blade.php outside view folder, all done, sorry for my clumsy still learning new thing haha
Related
There is an existing Livewire component and its corresponding blade file in the code structure.I want to create a new Laravel Controller and blade file.The blade files include variables that are defined in the Livewire component so when I return the newly created blade file from the new Laravel controller it shows undefined variable error.Is there any way to pass the variables defined in Livewire component in the newly created blade file?Also is there any alternative to this approach?
This is the blade file and the variable.
#if($variable)
#endif
This variable is defined the livewire component.
public $variable=false;
And the newly created controller is returning the above mentioned blade file.
Well I can't give you any definite answer because no code was posted and I don't know what your aim is
But if you really do need to pass variables to the new blade file, you can look into livewire browser events
https://laravel-livewire.com/docs/2.x/events
You can dispatch a browser event in the child component and listen for it in the parent
I once did this in a project of mine
$this->dispatchBrowserEvent('nationality-updated',['nationality' => $this->nationality]);
$this->dispatchBrowserEvent('state-updated',['state' => $this->state]);
And I listened to it in a parent component like this
<script>
window.addEventListener('nationality-updated',event => {
#this.set('state.nationality', event.detail.nationality)
})
window.addEventListener('state-updated',event => {
#this.set('state.state', event.detail.state)
})
</script>
Note that state.nationality is a livewire variable I accessed from Javascript and I'm not quite sure if that is optimal
But if you must you can follow the above
I have a button (anchor tag) in a VueJs component, when clicked, it routes to another page, loading a laravel blade view.
Inside vueJs component
Checkout
This route returns a laravel blade file.
Route::get('/checkout', function(){
return view('checkout');
});
Now I have a data property in my vueJs component which I would need to use in checkout blade view. How do I pass this data from vueJs component to Laravel blade view.
NB: I'm familiar with passing data from laravel to VueJs but not the reverse.
first of all the way you are trying, anchor tag is not a good way. and I donw know How Many data you need to send so I can suggest simple and easy way which is params.
suppose you need to send data id, name, address.
<a :href="'/checkout?id='+id+'&name='+name+'&address='+address">Checkout</a>
and in laravel
Route::get('/checkout', function(Request $request){
$data=$request->all()
return view('checkout')with('data',$data);
});
My 'homepage' for a Laravel install works great, which is: welcome.blade.php however, my question is - how do I get other basic 'static' pages to work correctly.
My preferred site top level navigation has for example, 'about us', so what I'd like to do is create a directory called 'about us' and then place a similar page as blade.index.php in there but it throws an error.
So, my question is - how do I name the file within a directory within the web application.
Thanks
You've got it flipped. blade always goes in the middle.
index.blade.php
return view('index');
/about/index.blade.php
return view('about.index');
You will need put your view file inside static folder of your choice and make sure your filename should contain blade in the middle for ex: "about.blade.php" and after that you will need to return that file with folder_name/file_name.
return view('Folder_name/File_name');
Try above code you are good to go.
I'm devising a small CMS for the in-house development team, where all have experience working with laravel.
The CMS requires a small feature where the services that are listed can have a quotation form attached. Instead of creating a completely separate module to add elements & other separately, I wanted to have the system in a manner that the developer adds the laravel collective form code, which we store in the database.
While retrieving, we render the form server side.
Here's my implementation
Controller
public function show($id)
{
$data['page'] = Service::where('slug', $id)->first();
if ($data['page']) {
....
$data['form'] = $data['page']->quoteform()->first();
....
And in the view
{!! $form['html'] !!}
But this is definitely won't help, so I tried this approach of rendering the collective form
$data['form'] = View::make('website.includes.render-form',['form'=>$data['page']->quoteform()->first()]);
But I'm not sure if this should work, as I couldn't make it work.
Looking forward to a solution if at all the approach I choose is possible, if yes or can be done, would like to know more on the same.
TIA
Edit 1:
I used the following blade command Blade::compileString('string here') which helped to a certain extent.
where I'm getting the following result
You can render the HTML of a view using render() method. So you can update to this :
$data['form'] = View::make('website.includes.render-form',
['form' => $data['page']->quoteform()->first()]
)->render();
Now the $data['form'] will have rendered HTML which you can use in blade using {!! $data['html'] !!} if you are passing $data to your main view.
I am using a different app.blade.php than the one provided with the default auth system in laravel. In the one I have created, I need to give a variable each time so that it show where we are in the code. For example, for my routes, I use:
Route::get('/', ['as' => 'home', function () {
$position = ['main_title'=>'Home','second_title'=>'',
'urls'=>
[
['name'=>'home','url'=>'#']
]
];
return view('home')->with('position',$position);
}]);
And in my app.blade.php, I can use this $position to print the main title etc.
Now the problem comes when I try to access login because $position is not set. How can I achieve that in Laravel so that the auth system will use my new blade system?
Thanks.
The auth views use the layout file app.blade.php located in resources/views/layouts. This is done by the code #extends('layouts.app') at top of all the views, which means that the auth views extend this layout.
To change the layout in all the auth views, manually replace the #extends('layouts.app') part at top with the new layout file you have created. For example if your new custom layout file is resources/views/base.blade.php, then replace the default extends to #extends('base').
If you want to use a variable in different (all) views, you may use ViewComposer