I am new to laravel and Web development i am making my a course project. thanx for helping
Its like a System which have different modules related to Inventory and POS and user can add and remove the items from the sidebar through customize setting tab
As Below Functionality is working
This Tab customize contain all the modules and along every item there is a checkbox when user click on the item checkbox it should be added to the sidebar and when unchecked it removes from the sidebar
Required
What i am Upto when user hit update and refresh page or even logout from the system and log in The Tab should be shown in sidebar
How can i achieve that part? does it relate to db .if yes please give me a way so that i can work
Code for Customize Tab
<div class="col-md-3 sidebar-customize">
<ul>
<li>
<a>
<input type="checkbox" id="customer" name="customer">
<i class="fa fa-print"></i>
<span>customer</span>
</a>
</li>
</ul>
</div>
Code of Jquery
$('input[type="checkbox"]').click(function () {
if(this.checked)
$('#customer').fadeIn(1000,function(){
$('#customer').css('overflow', 'none');
});
else
$('#customer').fadeOut();
});
I did something similar to this in a project I worked on where the sidebar could be minimized and we wanted this to be persisted across sessions and pages etc.
What we ended up doing was adding a table to keep track of their 'preferences'. This way we could save their choice to the database and then use this when loading the page to decide whether the sidebar should be minimized or not.
In your case, with this module approach - you could implement the same system.
I would create a new table to store the preference for each module in a column, something like this:
+----+---------+----------+-----------+----------+------------+------------+
| id | user_id | accounts | inventory | customer | created_at | updated_at |
+----+---------+----------+-----------+----------+------------+------------+
| 1 | 1 | 1 | 1 | 1 | today | today |
| 2 | 2 | 1 | 1 | 0 | today | today |
| 3 | 3 | 0 | 0 | 1 | today | today |
+----+---------+----------+-----------+----------+------------+------------+
This way you can link the module preferences as a relationship on your User
model and reference it directly in your views.
e.g
@if (Auth::user()->modules->accounts)
//User is currently user ID 1
show accounts menu
@endif
@if (Auth::user()->modules->accounts)
//User is currently user ID 3
do not show accounts menu
@endif
Because each value is stored as an integer in the database, and referenced as a 1 for yes and 0 for no, you can use it directly in an if
statement to decide if it should be shown or not.
Lastly, you just need to update your jQuery to fire an ajax call when the checkbox is clicked to update the setting/preference.