1

I am using laravel 5.1 for my project and till now it us going perfect until I wanted to use stored procedure in it.

so far I have gathered the information as

 $result = DB::select('call InsertNewApplicant(?????????????????????????)',
                    array($firstName, $middleName, $addressLine_1, $addressLine_2, $postCode, $landline, $mobile, $email,
                    $DOB, $maritalStatus, $industry, $occupation, $jobTitle, $selfEmployed, $selfAssessment, $workHome,
                    $ownTransport, $companyVehicle, $paySubs, $otherIncome, $printForms, $marketingUs, $marketingOther,
                    $agreedTNCs, $TNCVersion, $CampaignSource));

might be using this code for the controller to update any data from mysql, but as a beginner in Laravel, I have no idea where to define my stored procedure and in which file

I have visited many links , but all I could get is this code, not a single perfect example.

Can you please elaborate a small example on how to call a stored procedure in controller for a specific action?

and what all are prerequisite and other things that has to be taken care of

Jijo Nair
  • 828
  • 2
  • 11
  • 30

2 Answers2

0

Wow wow wow. You are using Laravel, so please don't write code like that. It's a sin!

Please read up on the following examples from the Laravel quickstart guide: https://laravel.com/docs/5.2/quickstart#eloquent-models https://laravel.com/docs/5.2/quickstart#creating-the-task

The first one is regarding Eloquent models (which you should definitely use) and the second one shows you how to store data in your database using these models.


Now on to the task at hand. I think that using

DB::statement(DB::raw("CALL InsertNewApplicant('$firstName', '$middleName');"));

and so on, so forth should do the trick...

theomessin
  • 754
  • 4
  • 13
0

Yes. Put it into a controller, and keep it this way until you would like to change something. Than you can abstract it out to dedicated class that may be mocked.

Yevgeniy Afanasyev
  • 37,872
  • 26
  • 173
  • 191