Bonjour chers tous,

Voila je rencontre un petit problème avec mon code.

Ce que je fais

je suis sur un projet test pour mieux apprendre laravel. j'utilise la version 8 de laravel.
en effet mon projet est de créer une application web de gestion de recrutement. je suis sur le module candat qui est en connexion avec 4 tables de ma base:
j'ai les tables

  • users(id, name, role_id) qui garde les paramètre du candidat
  • candidates(id, name, surname, user_id) qui enregistre l'id du candidat
  • experiences(id, company, candidate_id)
  • computers(id, software, candidate_id)
    -competences(id,quality, candidates_id).
    pour qu'un candidate s'enregistre il doit être au préalable connecté. il peut remplir la table candidates et remplir d'autres tables plutard.
    or je souhaite que lors de l'enregistres des tables computers, competences et experiences que mon application à partir de son user id qu'il recupère le candidate_is et insérer dans ce table. et l'enregistre ce fait avec cette vue experience
    **** ma vue *****
    @extends('applicant.templete1')
    @section('css')
    <link rel="stylesheet" type="text/css" href="{{asset('assets/css/main.css')}}"/>
    <script src="{{asset('assets/js/postuler.js')}}"></script>
    @endsection
    @section('content')

    <div id="container">

    <div id="fil-ariane"></div>
    <!-- DIV POUR AFFICHER LES ERREURS-->
    <div id="form-erreur">
      <p> Veuillez verifier les erreurs suivantes :</p>
      <ul id="form-content-erreur" class="form-content-erreur"></ul>
    </div>
    <!-- END DIV POUR AFFICHER LES ERREURS-->
    <div id="form-content">
        <form action="{{ route('experiences.store')}} " method="post" >
            @csrf
            <div class="bloc-form bloc-form5" >
                <div class="bloc-form bloc-form1" id="bloc-form1">
                    <div class="title"><h3>Experiences professionelles</h3></div>
                    <div class="content unique">
    
                            <div class="row-form">
                                <div class="field-nom required" >
                                    <label class="form-label" for="company">Company</label>
                                    <input type="text" class="form-input" name="company" id="company" placeholder="Your company" maxlength="100"/>
                                    <p class="field-erreur">Company cannot be empty</p>
                                </div>
                                <div class="field-prenom">
                                    <label class="form-label" for="function">Function</label>
                                    <input type="text" class="form-input" name="function" id="function" placeholder="function occupied" maxlength="100"/>
                                </div>
                            </div>
                            <div class="row-form">
                                <div class="field-datenaiss required" >
                                    <label class="form-label" for="location">Localisation</label>
                                    <input type="text" class="form-input" name="location" id="location" placeholder="location" />
                                    <p class="field-erreur">Location cannot be empty</p>
                                </div>
                                <div class="field-lieu required">
                                    <label class="form-label" for="duration">Duree</label>
                                    <input type="text" class="form-input" name="duration" id="duration" placeholder="Ex. Bafoussam"/>
                                </div>
                            </div>
                            <div class="row-form">
                                <div class="field-message  required" >
    
                                    <label for="implementation" >Realisation</label>
                                    <textarea  class="form-control  @error('implementation') is-invalid @enderror" name="implementation" id="message" placeholder="Your realisation" required rows=5 cols=50>{{ old('message') }}</textarea>
                                        @error('implementation')
                                            <div class="invalid-feedback">{{ $message }}</div>
                                        @enderror
                                </div>
    
                            </div>
    
                    </div>
                </div>
                <div class="bloc-form bloc-form2" >
    
                    <div class="title"><h3>Compétences professionnelle</h3></div>
                    <div class="content">
                        <div class="row-form">
                                <div class="field-nom required" >
                                    <label class="form-label" for="company">qualification</label>
                                    <input type="text" class="form-input" name="company" id="company" placeholder="Your company" maxlength="100"/>
                                    <p class="field-erreur">Company cannot be empty</p>
                                </div>
                                <div class="field-prenom">
                                    <label class="form-label" for="function">Reference</label>
                                    <input type="text" class="form-input" name="function" id="function" placeholder="function occupied" maxlength="100"/>
                                </div>
                            </div>
    
                    </div>
    
                    <div class="title"><h3>Connaissance informatique</h3></div>
                    <div class="content">
    
                        <div class="row-form">
                            <div class="field-nationalite  required">       
                                        <label class="form-label" for="software" >Software</label>
                                        <select class="form-input" name="software">
                                            <option value="-1">Sélectionner</option>
                                            <option value="1">Word</option>
                                            <option value="2">Excel</option>
                                            <option value="3">Outlook</option>
                                            <option value="4">Wester Union </option>
                                            <option value="5" selected="">CCASH</option>
                                            <option value="6">Small World</option>
                                            <option value="7">Transfast</option>
                                            <option value="8">Bankers Realm.Net</option>
                                            <option value="9">Maarch </option>
                                            <option value="10">GLPI</option>
                                            <option value="11">Team Collect</option>
                                        </select>
    
                            </div>
                                    <div class="field-nationalite  required">
                                        <label class="form-label" for="level" >Level</label>
                                        <select class="form-input" name="level">
                                            <option value="0">selectionner</option>
                                            <option value="1">Débutant</option>
                                            <option value="2">Intermédiaire</option>
                                            <option value="3" selected="">Avancé</option>
                                            <option value="4">Courant</option>
                                        </select>
                                    </div>
    
                        </div>
                    </div>
    
            </div>
            <div class="form-button">
                <span><input type="reset" > </input></span>
                <span><input type=button onclick=window.location.href="{{route('degrees.create')}}"; value= Next></span>
                <span><input type="submit" > </input></span>
            </div>
        </form>
    </div>

    </div>

@endsection
j'utilise un model par table
model Candidate
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Candidate extends Model
{
use SoftDeletes;
protected $table = 'candidates';
public $timestamps = true;

protected $fillable = [
    'civility','name','surname', 'city', 'country',  'user_id',
    'mobile', 'phone', 'quarter', 'email', 'birthdate', 'birthplace', 'child',
    'nationality','postbox', 'permit', 'cnps', 'matrimoniale'
];

/**
* One to Many relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
    return $this->belongsTo(User::class);
}

public function request()
{
    return $this->hasMany(Request::class);
}

public function Languages()
{
    return $this->hasMany(Language::class);
}

public function Experiences()
{
    return $this->hasMany(Experience::class);
}

public function Degrees()
{
    return $this->hasMany(Degree::class);
}

public function Cvtheques()
{
    return $this->hasMany(Cvtheque::class);
}

public function Certifications()
{
    return $this->hasMany(Certification::class);
}

public function Computers()
{
    return $this->hasMany(Computer::class);
}

public function Competences()
{
    return $this->hasMany(Competences::class);
}

public function jobs()
{
    return $this->belongsToMany(Job::class);
}

public function users()
{
    return $this->belongsToMany(User::class);
}

public function requests()
{
    return $this->belongsToMany(Request::class);
}

}

model competence
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Competence extends Model
{
use SoftDeletes;
protected $fillable = [
'quality','level', 'candidate_id',
];

public function candidate()
{
    return $this->belongsTo(Candidate::class);
}

}

model competence

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Computer extends Model
{
use SoftDeletes;
protected $fillable = [
'software','level', 'candidate_id',
];

public function candidate()
{
    return $this->belongsTo(Candidate::class);
}

}

model experience

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Experience extends Model
{
use SoftDeletes;
protected $fillable = [
'company','function','implementation', 'start_date', 'end_date', 'candidate_id',
];

public function candidate()
{
    return $this->belongsTo(Candidate::class);
}

}
j'utilisate les repositories
CandidateRepository
<?php

namespace App\Repositories;

use App\Models\Candidate;

class CandidateRepository {

protected $candidate;
/**
* Create a new CandidateRepository instance.
*
* @param \App\Models\Candidate $candidate
* @return void
*/
public function __construct(Candidate $candidate)
{
    $this->candidate = $candidate;
}

/**
* Get candidates collection.
*
* @return Illuminate\Support\Collection
*/
public function getPaginate($n)
{
    return $this->candidate->paginate($n);
}

/**
* Store a Candidate.
*
* @param array $inputs
* @return void
*/
public function store($inputs)
{
   return $this->candidate->create($inputs);
}

/**
* Update a Candidate.
*
* @param bool $seen
* @param int $id
* @return void
*/
public function update(Candidate $candidate, $inputs)
{
    $candidate->update($inputs);
}

public function destroy(Candidate $candidate)
{
    $candidate->delete();
}   

}
ComputerReposotory
<?php

namespace App\Repositories;

use App\Models\Computer;

class ComputerRepository {

protected $experience;
/**
* Create a new ComputerRepository instance.
*
* @param \App\Models\Computer $computer
* @return void
*/
public function __construct(Computer $computer)
{
    $this->computer = $computer;
}

/**
* Get candidates collection.
*
* @return Illuminate\Support\Collection
*/
public function getPaginate($n)
{
    return $this->computer->paginate($n);
}

/**
* Store a Candidate.
*
* @param array $inputs
* @return void
*/
public function store($inputs)
{
   return $this->computer->create($inputs);
}

/**
* Update a Candidate.
*
* @param bool $seen
* @param int $id
* @return void
*/
public function update(Computer $computer, $inputs)
{
    $computer->update($inputs);
}

public function destroy(Computer $computer)
{
    $computer->delete();
}   

}

CompetenceRepository
<?php

namespace App\Repositories;

use App\Models\Competence;

class CompetenceRepository {

protected $experience;
/**
* Create a new CandidateRepository instance.
*
* @param \App\Models\Candidate $candidate
* @return void
*/
public function __construct(Competence $competence)
{
    $this->competence = $competence;
}

/**
* Get candidates collection.
*
* @return Illuminate\Support\Collection
*/
public function getPaginate($n)
{
    return $this->competence->paginate($n);
}

/**
* Store a Candidate.
*
* @param array $inputs
* @return void
*/
public function store($inputs)
{
   return $this->competence->create($inputs);
}

/**
* Update a Candidate.
*
* @param bool $seen
* @param int $id
* @return void
*/
public function update(Competence $competence, $inputs)
{
    $competence->update($inputs);
}

public function destroy(Competence $competence)
{
    $competence->delete();
}   

}
je fais appel au request
candidateCreateRequest
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CandidateCreateRequest extends FormRequest
{
/**

  • Determine if the user is authorized to make this request.
  • @return bool
    */
    public function authorize()
    {
    return true;
    }

    /**

  • Get the validation rules that apply to the request.
  • @return array
    */
    public function rules()
    {
    return [
    'name' => ['bail','required', 'string', 'max:255'],
    'surname' => ['bail','required', 'string', 'max:255'],
    'civility' => ['bail','required', 'string', 'max:4'],
    'city' => ['bail','required', 'string', 'max:50'],
    'country' => ['bail','required', 'string', 'max:50'],
    'quarter' => ['bail','required', 'string', 'max:50'],
    'phone' => ['bail','required', 'string', 'max:15'],
    'email' => ['bail','required', 'string', 'email', 'max:255'],
    'birthdate' => ['bail','required', 'date'],
    'birthplace' => ['bail','required', 'string'],
    'nationality' => ['bail','required', 'string', 'max:100'],

    ];

    }
    }

CompetenceCreateRequest
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CompetenceCreateRequest extends FormRequest
{
/**

  • Determine if the user is authorized to make this request.
  • @return bool
    */
    public function authorize()
    {
    return true;
    }

    /**

  • Get the validation rules that apply to the request.
  • @return array
    */
    public function rules()
    {
    return [
    'quality' => ['bail', 'string', 'max:255'],
    'reference' => ['bail', 'string', 'max:255'],

    ];

    }
    }
    computerCreateRequest
    <?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class ComputerCreateRequest extends FormRequest
{
/**

  • Determine if the user is authorized to make this request.
  • @return bool
    */
    public function authorize()
    {
    return true;
    }

    /**

  • Get the validation rules that apply to the request.
  • @return array
    */
    public function rules()
    {
    return [
    'sofrware' => ['bail','string', 'max:50'],
    'level' => ['bail','string', 'max:50'],
    ];
    }
    }
    le tout géré par mon controleur
    experienceController
    <?php

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;
use App\Repositories\ExperienceRepository;
use App\Repositories\CompetenceRepository;
use App\Repositories\ComputerRepository;
use App\Http\Requests\ExperienceCreateRequest;
use App\Http\Requests\ExperienceUpdateRequest;
use App\Http\Requests\CompetenceCreateRequest;
use App\Http\Requests\CompetenceUpdateRequest;
use App\Http\Requests\ComputerCreateRequest;
use App\Http\Requests\ComputerUpdateRequest;
use App\Models\Experience;
use App\Models\Competence;
use App\Models\Computer;
use App\Models\Candidate;

class ExperienceController extends Controller
{
/**

  • The CandidateRepository instance.
  • @var \App\Repositories\CandidateRepository
    */
    protected $experienceRepository;
    protected $competenceRepository;
    protected $computerRepository;
    protected $nbrePerpage = 5;

    /**

  • Create a new CandidateController instance. *
  • @param \App\Repositories\CandidateRepository $CandidateRepository
  • @return void
    */
    public function __construct(experienceRepository $experienceRepository, competenceRepository $competenceRepository, computerRepository $computerRepository )
    {
    $this->experienceRepository = $experienceRepository;
    $this->competenceRepository = $competenceRepository;
    $this->computerRepository = $computerRepository;
    $this->middleware('auth');

    }

    /**

  • Display a listing of the candidates.
  • @return \Illuminate\Http\Response
    */
    public function index()
    {
    $candidate = Candidate::all();
    $experiences = $this->experienceRepository->getPaginate($this->nbrePerpage);
    return view('back.recruit.candidates.index', compact('candidates'));
    }

    /**

    • Show the form for creating a new resource.
    • @return \Illuminate\Http\Response
      */
      public function create()
      {
      $candidate = Candidate::all();
      return view('front.candidates.experience');
      }

    /**

    • Store a newly created resource in storage.
    • @param \Illuminate\Http\Request $request
    • @return \Illuminate\Http\Response
      */
      public function store(ExperienceCreateRequest $request, CompetenceCreateRequest $request1, ComputerCreateRequest $request2 )
      {

      $candidate = Candidate::where('user_id','=' (Auth::user()->id))->get()->first();

      $inputs = array_merge($request->all(), ['candidate_id' => $request->$candidate]);

      $experience = $this->experienceRepository->store($inputs);

      $inputs1 = array_merge($request1->all(), ['candidate_id' => $request1->$candidate]);

      $competence = $this->competenceRepository->store($inputs1);

      $inputs2 = array_merge($request2->all(), ['candidate_id' => $request2->$candidate]);

      $computer = $this->computerRepository->store($inputs2);

      return redirect()->route('degrees.create')->withOk('success', 'Degree created successfully! Poursuivre avec vos diplômes');
      }

    public function show(Candidate $candidate)
    {
    return view('back.recruit.candites.show', compact('candidate'));
    }

    public function edit(Candidate $candidate)
    {
    return view('front.candidates.edit', compact('candidate'));
    }

    /**

  • Update the specified Candidate in storage.
  • @param \Illuminate\Http\Request $request
  • @param int $id
  • @return \Illuminate\Http\Response
    */
    public function update()
    {

    }
    /**

  • Remove the specified contact from storage.
  • @param int $id
  • @return \Illuminate\Http\Response
    */
    public function destroy()
    {

    }
    }

Ce que je veux

pour qu'un candidate s'enregistre il doit être au préalable connecté. il peut remplir la table candidates et remplir d'autres tables plutard.
or je souhaite que lors de l'enregistres des tables computers, competences et experiences que mon application à partir de son user id qu'il recupère le candidate_id et insérer dans ce table.

Ce que j'obtiens

quand je valide ma vue: j'ai ce message d'erreur:
Call to undefined function =()
public function store(ExperienceCreateRequest $request, CompetenceCreateRequest $request1, ComputerCreateRequest $request2 )
{

   $candidate = Candidate::where('user_id','=' (Auth::user()->id))->get()->first();

   $inputs = array_merge($request->all(), ['candidate_id' => $request->$candidate]);

je me tourne vers vous pour avoir une solution car je suis bloqué sur ce module depuis trois jours sans succès.
merci d'avance.

1 réponse


salut alors si cela peut t'aider il faudra essayer de faire de l'i,njection de dependance