Skywalskurt

Skywalskurt

Member Since 3 Months Ago

Experience Points
290
Total
Experience

4,710 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
290 XP
Jul
02
1 week ago
Activity icon

Started a new Conversation Maatwebsite Excel/Laravel - Downloading Excel Not Working With AJAX Call

Hello,

I'm developing web application with Laravel and i have some issue with the Maatwebsite export excel with an AJAX call : i don't understand why the file is not upload because i don't have any error message and the AJAX call seems to work fine.

Here is the AJAX call in the view :

            $.ajax({
                type:"post",
                url: btnExportExcel.attr('data-url-export'),
                dataType: "json",
                responseType:'blob',
                data: {
                    projetsJSON: JSON.stringify(projets)
                },
                success:function() {
                    console.log("success");
                }
            })

The controller :

    /**
     * Fonction d'export Excel
     * @return Excel
     */
    public function exportExcel(Request $request) {
        return Excel::download(new ProjetsExport($request),'projets'. date('Y-m-d') . '.xlsx');
    }

And the "ProjetExport" class :

<?php

namespace App\Exports;

use App\Models\Projet;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class ProjetsExport implements FromArray, WithHeadings, WithMapping
{

    protected $request;
    
    public function __construct($request)
    {
        $this->request = $request;
    }
    
    /**
    * @return array
    */
    public function array():array
    {   
        $projets = json_decode($this->request->projetsJSON);
        return $projets;
    }

    /**
     * Initialisation des headers des colonnes du fichier Excel.
     */
    public function headings(): array
    {
        return ['Libellé','Date de création','Date de fin','Budget HT','Objectif','Etat','Type','Ouverture','Chef de projet','Famille'];
    }

    /**
     * Formattage des données.
     */
    public function map($row): array
    {
        return [
            $row->libelle,
            (new \DateTime($row->dt_creation))->format('d/m/Y'),
            (new \DateTime($row->dt_fin))->format('d/m/Y'),
            $row->budget_ht,
            $row->obj_collect,
            $row->type_proj,
            $row->ouverture,
            $row->chef_proj,
            $row->famille
        ];
    }
    
}

If someone have an idea or some clue to help me, because i'm a bit stuck right now. Thanks in advance !

Activity icon

Replied to Ajax Return Is Not Downloading The Excel File Using Maatwebsite In Laravel

Hi sorry this is an old subject but i have the same issue, excel file is not downloading after AJAX call... Do you find the solution of the problem or not ?

Here is the ajax call :

            $.ajax({
                type:"post",
                url: btnExportExcel.attr('data-url-export'),
                dataType: "json",
                responseType:'blob',
                data: {
                    projetsJSON: JSON.stringify(projets)
                },
                success:function() {
                    console.log("success");
                }
            })

The controller :

    /**
     * Fonction d'export Excel
     * @return Excel
     */
    public function exportExcel(Request $request) {
        return Excel::download(new ProjetsExport($request),'projets'. date('Y-m-d') . '.xlsx');
    }

The "ProjetExport" file :

<?php

namespace App\Exports;

use App\Models\Projet;
use Maatwebsite\Excel\Concerns\FromArray;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class ProjetsExport implements FromArray, WithHeadings, WithMapping
{

    protected $request;
    
    public function __construct($request)
    {
        $this->request = $request;
    }
    
    /**
    * @return array
    */
    public function array():array
    {   
        $projets = json_decode($this->request->projetsJSON);
        return $projets;
    }

    /**
     * Initialisation des headers des colonnes du fichier Excel.
     */
    public function headings(): array
    {
        return ['Libellé','Date de création','Date de fin','Budget HT','Objectif','Etat','Type','Ouverture','Chef de projet','Famille'];
    }

    /**
     * Formattage des données.
     */
    public function map($row): array
    {
        return [
            $row->libelle,
            (new \DateTime($row->dt_creation))->format('d/m/Y'),
            (new \DateTime($row->dt_fin))->format('d/m/Y'),
            $row->budget_ht,
            $row->obj_collect,
            $row->type_proj,
            $row->ouverture,
            $row->chef_proj,
            $row->famille
        ];
    }
    
}

If you can help me, that will be great, i'm a bit stuck right now... :(

Jun
30
1 week ago
Activity icon

Replied to Laravel 5.8 - Carbon / Unexpected Data Found. Unexpected Data Found

Hi thanks for your answer. Why what's the matter with Laravel 5.8 ? It's not recommended ?

For the issue, i have solved by casting the date in the model :

'DT_DELIB' => 'datetime:d/m/Y'
Activity icon

Started a new Conversation Laravel 5.8 - Carbon / Unexpected Data Found. Unexpected Data Found

Hello,

I'm developing a Laravel application (version 5.8) and i have some issues with the createFromFormat Carbon's method in Internet Explorer 11 (yeah, i know... but this is the default browser of my company).

Here is the piece of code where i got the error and the stack trace of the error :

$datas['DT_DELIB'] = Carbon::createFromFormat('d/m/Y',$delibProjRequest->DT_DELIB)->toDateTimeString();
InvalidArgumentException 
Unexpected data found. Unexpected data found. Unexpected data found.
InvalidArgumentException thrown with message "Unexpected data found.
Unexpected data found.
Unexpected data found."

Stacktrace:
#56 InvalidArgumentException in C:\laragon\www\projetMecenat\vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:623
#55 Carbon\Carbon:rawCreateFromFormat in C:\laragon\www\projetMecenat\vendor\nesbot\carbon\src\Carbon\Traits\Creator.php:645
#54 Carbon\Carbon:createFromFormat in C:\laragon\www\projetMecenat\app\Http\Controllers\DeliberationProjetController.php:50
#53 App\Http\Controllers\DeliberationProjetController:store in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
#52 call_user_func_array in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54
#51 Illuminate\Routing\Controller:callAction in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\ControllerDispatcher.php:45
#50 Illuminate\Routing\ControllerDispatcher:dispatch in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Route.php:219
#49 Illuminate\Routing\Route:runController in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Route.php:176
#48 Illuminate\Routing\Route:run in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Router.php:680
#47 Illuminate\Routing\Router:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
#46 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php:41
#45 Illuminate\Routing\Middleware\SubstituteBindings:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#44 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#43 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php:75
#42 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#41 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#40 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php:49
#39 Illuminate\View\Middleware\ShareErrorsFromSession:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#38 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#37 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php:56
#36 Illuminate\Session\Middleware\StartSession:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#35 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#34 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php:37
#33 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#32 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#31 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php:66
#30 Illuminate\Cookie\Middleware\EncryptCookies:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#29 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#28 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
#27 Illuminate\Pipeline\Pipeline:then in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Router.php:682
#26 Illuminate\Routing\Router:runRouteWithinStack in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Router.php:657
#25 Illuminate\Routing\Router:runRoute in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Router.php:623
#24 Illuminate\Routing\Router:dispatchToRoute in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Router.php:612
#23 Illuminate\Routing\Router:dispatch in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:176
#22 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:30
#21 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php:65
#20 Barryvdh\Debugbar\Middleware\InjectDebugbar:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#19 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#18 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21
#17 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#16 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#15 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php:21
#14 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#13 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#12 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php:27
#11 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#10 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#9 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php:62
#8 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#7 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#6 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\fideloper\proxy\src\TrustProxies.php:57
#5 Fideloper\Proxy\TrustProxies:handle in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:163
#4 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Routing\Pipeline.php:53
#3 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php:104
#2 Illuminate\Pipeline\Pipeline:then in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:151
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in C:\laragon\www\projetMecenat\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in C:\laragon\www\projetMecenat\public\index.php:55

And when i dump the data passed in parameter i got (in IE and others browser) :

dd($delibProjRequest->DT_DELIB);
// "‎21‎/‎07‎/‎2020"

The strange thing is when i try with a date that have the same format, it seems to work :

$test = Carbon::createFromFormat("d/m/Y",'20/07/2019');
dd($test);
/**
Carbon\Carbon @1563608837 {#405 ▼
  #constructedObjectId: "000000006b8ef720000000002bcf1ddf"
  #localMonthsOverflow: null
  #localYearsOverflow: null
  #localStrictModeEnabled: null
  #localHumanDiffOptions: null
  #localToStringFormat: null
  #localSerializer: null
  #localMacros: null
  #localGenericMacros: null
  #localFormatFunction: null
  #localTranslator: null
  #dumpProperties: array:3 [▶]
  #dumpLocale: null
  date: 2019-07-20 07:47:17.0 UTC (+00:00)
  timezone_type: 3
  timezone: "UTC"
*/

I think that this is something particular with IE 11 because it works fine in others browsers. If someone got an idea or clues to help it will be great, i'm a bit stuck right now...

Thanks in advance.

Jun
09
1 month ago
Activity icon

Replied to Laravel 5.8 / Route Not Found (404 Error) But Exist

Ok, i got it. I was sending a wrong parameter to the controller... Weird that it raise a 404 error, but the issue is fixed! Thanks all

Activity icon

Replied to Laravel 5.8 / Route Not Found (404 Error) But Exist

@munazzil i have try this before, still not working...

yes sorry i don't have paste the good route that return the error in my first post i have edited it @siangboon. The route where i got the problem is the destroy route and it's a GET method

Activity icon

Replied to Laravel 5.8 / Route Not Found (404 Error) But Exist

yeah that's why i'm going to do @nakov, because can't understand that

Activity icon

Replied to Laravel 5.8 / Route Not Found (404 Error) But Exist

Hi thanks for answer and precise me this Exception but this is not this error that is raised (it's a 404 error). I check and i have data that correspond to the parameters.

As i precise in my post, the dd is wanted for checking if the controller is called (and it's called because my dump is display), but when i remove it, i got the 404 error...

But thanks anyway :) @michaloravec

Activity icon

Started a new Conversation Laravel 5.8 / Route Not Found (404 Error) But Exist

Hello,

I'm looking for some help because i can't understand a 404 error that i got when i run some route. So here is the route that return the error :

Route::get('/delibProj/delete/projet/{idProj}/delib/{idDelibProj}','[email protected]')->name('delibProj.destroy');

i don't think that i have conflict with others routes :

Route::get('/projets','[email protected]')->name('projets.index');
Route::get('/projets/create','[email protected]')->name('projets.create');
Route::post('/projets/{redirect}','[email protected]')->name('projets.store');
Route::post('/projets/{projet}/{redirect}','[email protected]')->name('projets.update');
Route::get('/projets/{projet}/edit','[email protected]')->name('projets.edit');
Route::get('/projets/export/json','[email protected]')->name('projets.json');
Route::post('/projets/export/excel', '[email protected]')->name('projets.exportExcel');
Route::get('/projets/{idProjet}/edit/delibContrepartie','[email protected]')->name('projets.delibContrepartie');
Route::get('/projets/delete/{idProjet}','[email protected]')->name('projets.destroy');

Route::post('/deliberations/projet/{idProjet}','[email protected]')->name('projets.delibs');
Route::post('/tranches/projet/{idProjet}','[email protected]')->name('projets.tranches');
Route::post('/contreparties/projet/{idProjet}','[email protected]')->name('projets.contreparties');

Route::get('/delibProj/delete/projet/{idProj}/delib/{idDelibProj}','[email protected]')->name('delibProj.destroy');

The strange thing is that it was working yesterday and also when i put a dd (dump an die) in the method of the controller that is called i got the message of the dump.

Code of the controller :

    public function destroy($idProj,$idDelibProj) 
    {
        dd("call destroy method from controller");
        $delibProj = DelibProj::findOrFail($idDelibProj);
        $projet = Projet::findOrFail($idProj);
        $delibProj->delete();
        return redirect()->route('projets.delibContrepartie',['idProjet' => $idProj])->with('info','La délibération n°' . $idDelibProj . ' du projet ' . $projet->LIBELLE_PROJ . ' a bien été supprimée');
    }

If someone can help me to understand and fixe this, that will be great ! :)

Mar
18
3 months ago
Activity icon

Replied to Insertion Error Foreign Key

@usmanbasharal

<?php

/**
 * Created by Reliese Model.
 */

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

/**
 * Class Projet
 * 
 * @property int $ID_PROJET
 * @property int $ETAT_PROJ_
 * @property string $LIBELLE_PROJ
 * @property int $CHEF_PROJ_
 * @property Carbon $DT_CREATION
 * @property Carbon $DT_FIN
 * @property float $BUDGET_HT
 * @property int $FAMILLE_
 * @property int $OBJ_COLLECT
 * @property int $OUVERTURE_
 * @property int $TYPE_PROJ_
 * @property int $PORTEUR_
 * @property Carbon $DTNEW
 * @property Carbon $DTMAJ
 * @property string $UTILNEW
 * @property string $UTILMAJ
 * 
 * @property Collection|Contrepartie[] $contreparties
 * @property Collection|DelibProj[] $delib_projs
 * @property Collection|Don[] $dons
 * @property Collection|Tranche[] $tranches
 *
 * @package App\Models
 */
class Projet extends Model
{
	protected $table = 'projet';
	protected $primaryKey = 'ID_PROJET';
	public $incrementing = false;
	public $timestamps = false;

	protected $casts = [
		'ID_PROJET' => 'int',
		'ETAT_PROJ_' => 'int',
		'CHEF_PROJ_' => 'int',
		'BUDGET_HT' => 'float',
		'FAMILLE_' => 'int',
		'OBJ_COLLECT' => 'int',
		'OUVERTURE_' => 'int',
		'TYPE_PROJ_' => 'int',
		'PORTEUR_' => 'int'
	];

	protected $dates = [
		'DT_CREATION',
		'DT_FIN',
		'DTNEW',
		'DTMAJ'
	];

	protected $fillable = [
		'ETAT_PROJ_',
		'LIBELLE_PROJ',
		'CHEF_PROJ_',
		'DT_CREATION',
		'DT_FIN',
		'BUDGET_HT',
		'FAMILLE_',
		'OBJ_COLLECT',
		'OUVERTURE_',
		'TYPE_PROJ_',
		'PORTEUR_',
		'DTNEW',
		'DTMAJ',
		'UTILNEW',
		'UTILMAJ',
		'ID_USER'
	];

	public function contreparties()
	{
		return $this->hasMany(Contrepartie::class, 'ID_PROJET');
	}

	public function delib_projs()
	{
		return $this->hasMany(DelibProj::class, 'ID_PROJET');
	}

	public function dons()
	{
		return $this->hasMany(Don::class, 'ID_PROJET');
	}

	public function tranches()
	{
		return $this->hasMany(Tranche::class, 'ID_PROJET');
	}
}


Activity icon

Replied to Insertion Error Foreign Key

Oh great! That was so easy, thanks @deansatch :)

Activity icon

Started a new Conversation Insertion Error Foreign Key

Hi,

I'm looking for some help because i don't understand this error : i want to insert a new data in a table with a form and this table have a foreign key with an other table. The value of this foreign key come from the form also as the others field ; but when i validate my form i got an error

Field 'ID_USER' doesn't have a default

But the thing that i don't understand is that when i dump the request from the form, i have a value for the ID_USER...

I put you my code : The store function form the controller :

    public function store(ProjetRequest $projetRequest)
    {
        $datas = $projetRequest->all();
        $datas['DTNEW'] = Carbon::now();
        $datas['DTMAJ'] = Carbon::now();

        Projet::create($datas);
        return redirect()->route('projets');
    }

And the part of the form where the ID_USER is :

                <div class="col-3">
                    <select name="ID_USER" id="" class="form-control form-control-sm" required>
                        @foreach($chargesMecenats as $charge)
                            <option value="{{ $charge->ID_USER }}">{{ $charge->LASTNAME }} {{ $charge->FIRSTNAME }}</option>
                        @endforeach
                    </select>
                </div>

Thanks in advance for your help! :)