skip to Main Content

Ihave the following code which displays the notifications :

<div class="position-relative d-inline-block">
                <button class="header-icon btn btn-empty" type="button" id="notificationButton"
                data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <i class="simple-icon-bell"></i>
                    <span class="count">{{$contrats_expires_count}}</span>
                </button>
                <div class="dropdown-menu dropdown-menu-right mt-3 position-absolute abc" id="notificationDropdown">
                    
                    @foreach($contrats_expires as $contrats_expires)
                      <a href="{{ route('getcontrat', $contrats_expires->id_contrat) }}">  
                        <div class="d-flex flex-row mb-3 pb-3 border-bottom">

                            <a href="{{ route('getcontrat', $contrats_expires->id_contrat) }}">
                                <img src="{{ '/castingimages/' . $contrats_expires->photo. ''}}" alt="Notification Image"
                                class="img-thumbnail list-thumbnail xsmall border-0 rounded-circle" />
                            </a>
                            <div class="pl-3">
                                <a href="{{ route('getcontrat', $contrats_expires->id_contrat) }}">
                                    <p class="font-weight-medium mb-1">{{$contrats_expires->nom}} {{$contrats_expires->prenom}}</p>
                                    <p class="text-muted mb-0 text-small">{{$contrats_expires->numero_projet}} {{$contrats_expires->numero_contrat}}</p>
                                </a>
                            </div>

                        </div>
                    </a>
                  @endforeach    
                </div>
            </div>

So now I’m trying to when I click on a notification get the if of the clicked notification and display data according to this id on another page.

So I Have the following route :

Route::group(['middleware' => ['auth','role:account_manager|admin|manager_de_filiale']], function() { 
    Route::get('/contrat/{id_contrat}', [AppHttpControllersDashboardController::class, 'getContrat'])->name('getcontrat');
});

And thefollowing controller :

 public function getContrat(Rquest $request, $id_contrat){

    if(request()->ajax())
    {
       return datatables()->of(Contrat::where('contrats.id_contrat',$id_contrat)->leftjoin('projets_castings', 'contrats.id_contrat', '=', 'projets_castings.id_contrat')->leftjoin('castings', 'castings.id_casting', '=', 'projets_castings.id_casting')->leftjoin('projets','projets.id_projet','=','projets_castings.id_projet')->leftjoin('modele_contrat','modele_contrat.id_modele_contrat','=','contrats.id_modele_contrat')->select('contrats.numero_contrat','castings.nom','modele_contrat.modele_contrat','contrats.date_signature','contrats.lieu_signature','contrats.paye','contrats.date_paiement','contrats.created_at','contrats.actif','projets_castings.type_contrat','projets_castings.id_projet_casting','projets_castings.id_contrat','contrats.date_fin_contrat','projets.numero_projet','projets_castings.type_contrat','contrats.id_contrat')->latest()->get())
       
            ->addColumn('action', function($data){
                $button = '<table><tr><td>';
                        $button .= '<button type="button" name="edit" id="'.$data->id_contrat.'" class="edit btn btn-primary btn-sm">Modifier</button>';
                         
                $button .= '</td><td>';
                  /*$button .= '<button type="button" name="download" id="'.$data->id_contrat.'" class="download btn btn-primary btn-sm">Télécharger</button>';*/

                  $button .='<a href="list_contrats/'.$data->id_contrat.'/download" class="download btn btn-primary btn-sm"  data_id="'.$data->id_contrat.'" >Télécharger</a>';
                         
                $button .= '</td><td>';
                $button .= ' <label  class="switch" >';
                       $button .= '  <input type="checkbox" id="'.$data->id_contrat.'" class="switch selectRow" ';
                 
                        
                
                if ($data->actif == 1) {

                    $button .= "checked";
                }

                $button .= '><span class="slider round"></span></label>';
                $button .= '</td></tr></table>';

                return $button;
        })->addColumn('payee', function($data){
               $button1 = '<table><tr><td>';
                $button1 .= ' <label  class="switch" >';
                       $button1 .= '  <input type="checkbox" id="'.$data->id_contrat.'" class="switch selectRow1" ';

                if ($data->paye == 1) {

                    $button1 .= "checked";
                }

                $button1 .= '><span class="slider round"></span></label>';
                $button1 .= '</td></tr></table>';

                return $button1;
        })
        ->rawColumns(['action','payee','type_contrat'])
        ->make(true);

       }
      $modeles_contrat = Model_Contrat::where('id_filiale',Auth::user()->id_filiale)->latest()->get();

    return view('Contrat_files.contrats')->with('modeles_contrat', $modeles_contrat);
    
}

And the following script in my blade view :

<script>

   $(document).ready(function(){
/**************afficher les données **********************/
var $tabledata =   $('.data-table-feature').DataTable({
        destory: true,
        processing: true,
        serverSide: true,
        ajax:{
         url: "{{ route('contrat.getContrat') }}",
         type: "GET",
        },
        columns:[
        
         {
            data: 'numero_contrat',
            name: 'numero_contrat',
            orderable: false
         },
         {
            data: 'numero_projet',
            name: 'numero_projet',
            orderable: false
         },
         {
            data:'nom',
            name: 'nom'
         },
         {
            data: 'modele_contrat',
            name: 'modele_contrat'
         },
         {
           data:   'date_signature',
           name:   'date_signature'
         },
         {
           data:   'date_fin_contrat',
           name:   'date_fin_contrat'
         },
          {
           data:   'lieu_signature',
           name:   'lieu_signature'
         },
         
         {
            data: 'payee',
            name: 'payee',
            orderable: false
         },
         {
            data: 'date_paiement',
            name: 'date_paiement',
            orderable: false
         },
         {
           data:   'action',
           name:   'action',
             orderable: false
         }
        ] 
       });
       });
     </script>

And the following route:

Route::group(['middleware' => ['auth','role:account_manager|admin|manager_de_filiale']], function() { 
   Route::get('contrat', [AppHttpControllersDashboardController::class, 'getContrat'])->name('contrat.getContrat');
});

SoI get the following error :GET http://localhost:8000/contrat/189%7D 404 (Not Found)

I don’tknow where is the error in my code , if you have any idea ,please help.

2

Answers


  1. You have to correct the blade file code URL:

     url: "{{ route('contrat.getContrat') }}",
    

    to

    {{ route('contrat.getContrat',[$id_contrat]) }}
    

    you have an argument in route and controller function $id_contact, so you need to pass this parameter in URL.

    Login or Signup to reply.
  2. Try writing your route like this:

        Route::group(['middleware' => ['auth','role:account_manager|admin|manager_de_filiale']], function(){ 
         Route::get('contrat', 'DashboardController@getContrat')->name('contrat.getContrat');
    
         Route::get('/contrat/{id_contrat}', 'DashboardController@getContrat')->name('contrat.getcontrat');
        });
    

    This might work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search