I created an a tag and i want it to have double functionality, open a modal with bootstrap and also run a backend spring controller method
<a class="btn btn-info" th:attr="data-bs-target='#editarPersonaModal'" data-bs-toggle="modal"
th:href="#{/editarPersona?id=}+${persona.id}">Editar</a>
and my controller:
#GetMapping("/editarPersona")
public void openEditarPersonaModal(#RequestParam String id){
this.idPersonaEditar = Long.valueOf(id);
System.out.println("Accediste ruta editarPersona");
}
when i access to that route through the tag method th:href it doesn't show the message "Aceediste ruta editarpersona" in the console but it opens the modal
<a class="btn btn-info" th:attr="data-bs-target='#editarPersonaModal'" data-bs-toggle="modal"
th:href="#{/editarPersona?id=}+${persona.id}">Editar</a>
So what I'm trying to do is delete a row from my database table with a icon button (href)
<span title="Delete Task"><i class="far fa-trash-alt"></i></span>
Here is my controller
public function destroy($idtask) {
DB::delete('delete from tasks where idtask = ?',[$idtask]);
return redirect('/todo/notstarted');
}
and here is my routing:
Route::get('notstarted/delete/{idtask}','NotstartedController#destroy');
so my button is on page /todo/notstarted , when i click it it goes to /todo/notstarted/delete/1 like I want but it shows the laravel 404|Not Found page. Normally the redirect in my controller should work but for some reason it broke.
here is a picture of my folder structure of my views:
enter image description here
Hopefully someone can help!
the problem is your anchor tag's href
you should use laravel url() helper.
like the code below :
<a href="{{url('notstarted/delete/',$task->idtask)}}" style="color: #8B0000">
<span title="Delete Task"><i class="far fa-trash-alt"></i></span>
</a>
I'm making a College Administration website where a professor can log in.
I have a dashboard, where my dynamically generated button should be placed: (right now it just has dummy buttons!)
Generated by this view file, which I will have to modify soon:
<div class="container d-flex flex-column align-items-center justify-content-center">
<h1>IA DASHBOARD</h1>
<br>
<div class="grid2">
SUBCODE 1</button>
SUBCODE 2</button>
SUBCODE 3</button>
</div>
Tables in the Database:
the table iamarks contains the data (student info, and marks) that is to be displayed after /subcode/{subcode} narrows it down to records of just the students that are in the class assigned to current logged-in professor.
classroom_mappers is a table used to map a professor to a classroom with a subject. It makes sure that one classroom only has one professor for a particular subject.
the routes currently in my web.php:
route::get('/ia', 'IAController#show')->middleware('auth');
Route::get('/subcode/{subcode}', 'IAController#showTable')->middleware('auth');
...and these are the methods inside my controller:
//shows buttons to the user:
public function show(){
$subcodes = DB::table('classroom_mappers')
->select('subcode')
->where([['PID','=', auth()->user()->PID]])
->get();
return view('ia',compact('subcodes'));
}
//when user clicks a button, subcode is to be generated and a table is to be shown:
//it works, I tried it by manually typing in subcode value in URL.
public function showTable($subcode){
$sem = DB::table('classroom_mappers')
->where([['PID','=', auth()->user()->PID],
['subcode','=',$subcode]])
->pluck('semester');
$division = DB::table('classroom_mappers')
->where([['PID','=', auth()->user()->PID],
['semester','=',$sem],
['subcode','=',$subcode]])
->pluck('division');
$data = DB::table('iamarks')
->where([['semester','=',$sem],
['division','=',$division],
['subcode','=',$subcode]])
->get();
return view('subcode',compact('data'));
}
My Problem:
To be able to generate the {subcode} in the URL dynamically, I want to create buttons in the dashboard using the data $subcodes. The controller hands over the $subcodes (an array of subject codes which belong to logged in professor) which are to be made into buttons from the show() method.
The buttons should have the name {subcode} and when clicked, should append the same subject code in the URL as {subcode}.
How do I make use of $subcodes and make the buttons dynamically?
How do I make sure the buttons made for one user are not visible to another user?
I managed to find the solution, thanks to Air Petr.
Apparently, you can't nest blade syntax like {{some_stuff {{ more_stuff }} }} and it generates a wrong php code. I modified the solution by Air Petr to:
<div class="grid2">
#foreach ($subcodes as $subcode)
<a href="<?php echo e(url('/subcode/'.$subcode->subcode));?>">
<button class="btn btn-outline-primary btn-custom-outline-primary btn-custom">
<?php
echo e($subcode->subcode);
?>
</button>
</a>
#endforeach
</div>
It generates the buttons perfectly. The buttons for one user are not visible to another, since I'm using PID constraint in a query (['PID','=', auth()->user()->PID]).
Pass the passcodes array to view:
$subcodes = []; // Array retrieved from DB
return view('subcode', compact('subcodes'));
And in subcode.blade.php, loop through each subcode:
<div class="grid2">
#foreach($subcodes as $subcode)
<a href="{{ url('/subcode/' . $subcode->subcode) }}">
<button class="btn btn-outline-primary btn-custom-outline-primary btn-custom">SUBCODE {{ $subcode->subcode }}</button>
</a>
#endforeach
</div>
You can loop your codes to create buttons. Something like this (it's for "blade" template engine):
<div class="grid2">
#foreach ($subcodes as $subcode)
{{ $subcode->subcode }}</button>
#endforeach
</div>
Since you're using PID constrain in a query (['PID','=', auth()->user()->PID]), you'll get buttons for that specific PID. So there's no problem.
I found a weird problem in my project. I'm using Spring MVC, Tiles, JSPX and Boostrap.
I have a navbar in my header page, then I added a span to show a badge like https://getbootstrap.com/docs/3.3/components/#badges.
Till here nothing strange. But If I add an id on span tag and there is an error inside the html code, I can't see any log or exception.
Here the code
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
<span class="fa fa-male"><jsp:text/></span>
<span class="badge badgeNavbar" id="badgesContrattiDaApprovare">
<jsp:text/>
</span> ${clienti}
<span class="caret"><jsp:text/></span>
</a>
<ul class="dropdown-menu">
...
</ul>
Instead If I remove id="badgesContrattiDaApprovare" I can see the exceptions.
Are there any conflicts between span and id?
SO: Why if I add the id attribute to the span inside bootstrap navbar the JSP/Tiles exceptions aren't shown inside the rendered view?
For example here if an exception occurs without the id attribute:
Instead, if I add the id attribute is like the rendering is stopped, and I see only a blank page. The generated/rendered html code is incomplete.
im using panel collapse in bootstrap and has a parent category and child category
The parent was display for panel-title and the child categories was display on the panel-collapse to perform an ajax to load posts under child category
<h4 class="panel-title">
<a data-toggle="collapse" href="#collapse1">Parent categories</a>
</h4>
<div id="collapse1" class="panel-collapse collapse">
<a onclick(perform ajax event)><li>child categories</li>
</div>
my problem was on page load all post was executed already. i just want only to show the post of the array 0 or to load an ajax on page load