jhutto

jhutto

Member Since 9 Months Ago

Experience Points 6,180
Experience Level 2

3,820 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 46
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

21 Mar
13 hours ago

jhutto left a reply on Processing API Array With Multi-dimensional Array

Sorry... meant to put what I tried... It's not working.

foreach($persons as $key => $value){

           


           $data[$key] = array(
               "@id" => $value['@id'],
               "FirstName" => $value['firstName'],
               "middleName" => $value['middleName'],
               "goesByName" => $value['goesByName'],
               "gender" => $value['gender'],
               "address1" => $value['addresses']['address']['0']['address1'],
               "address2" => $value['addresses']['address']['0']['address2'],
               "city" => $value['addresses']['address']['0']['city'],
               "state" => $value['addresses']['address']['0']['stProvince'],
               "zip" => $value['addresses']['address']['0']['postalCode'],
               "householdposition" => $value['householdMemberType']['name'],
               "status" => $value['status']['name'],
            
            );
            
            $Communications = $value['Communications']['Communication'];
            foreach($Communications as => $Communication){

                $datacommunications = array(
                    "householdposition" => $value['householdMemberType']['name'],

                );


            }
           
            
        };

jhutto started a new conversation Processing API Array With Multi-dimensional Array

I'm working on an app, that is pulling data from an API of an online application we use. I retrieving this long array from the app but I'm still new to this and not sure what's the best way to process the multi-dimensional array. This issue is getting to the data that is buried deep within the array. Any ideas you be helpful.

I've tried create a single array and but then I can't seem to get the foreach loop inside of the inserting the data into another array...

I need to be able to process through theses sections which have multiple records. "addresses" => array:2 [▶] "communications" => array:3 [▶]

Here's the data that is being returned....

array:4 [▼
  0 => array:40 [▼
    "@id" => "1075701652"
    "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075701652"
    "@imageURI" => ""
    "@oldID" => "23260046"
    "@iCode" => "q2B9Wy7iRRK7F8b2C5DfKg=="
    "@householdID" => "1046151597"
    "@oldHouseholdID" => "15023395"
    "title" => null
    "salutation" => null
    "prefix" => null
    "firstName" => "Michael"
    "lastName" => "Angel"
    "suffix" => null
    "middleName" => null
    "goesByName" => null
    "formerName" => null
    "gender" => "Male"
    "dateOfBirth" => "2005-04-07T00:00:00"
    "maritalStatus" => "Child/Yth"
    "householdMemberType" => array:3 [▶]
    "isAuthorized" => "true"
    "status" => array:6 [▶]
    "occupation" => array:4 [▶]
    "employer" => null
    "school" => array:3 [▶]
    "denomination" => array:3 [▶]
    "formerChurch" => null
    "barCode" => null
    "memberEnvelopeCode" => null
    "defaultTagComment" => null
    "weblink" => array:3 [▶]
    "solicit" => null
    "thank" => "true"
    "firstRecord" => "2009-01-30T09:37:22"
    "attributes" => array:1 [▶]
    "addresses" => array:1 [▶]
    "communications" => array:1 [▶]
    "lastMatchDate" => null
    "createdDate" => "2015-12-14T12:07:53"
    "lastUpdatedDate" => "2015-12-14T12:07:53"

Thanks for your help.

18 Mar
3 days ago

jhutto left a reply on Retrieve Multiple Data Using Ajax Data From Controller

As usual.. You guys respond quickly and send me down the right path. Thanks for all the reply's.

jhutto started a new conversation Retrieve Multiple Data Using Ajax Data From Controller

I'm using ajax to post a payment into mysql database with laravel controller. This is working fine. Now I'm trying to make pass more that one variable back to ajax to use in the view. Can you send more than one data item back to the ajax code in the view.

This works just fine.

 $.ajax({
                        url: "/somaspayments/payment",
                        type: "POST",
                        data: $form_data,
                        cache: false,
                        success: function (data) {
                                //alert('Your data updated');
                                data = JSON.parse(data);
                                console.log(data);
});

Controller: This works too.. It post the payments to the database. and will return all the payments made and then I can process the json data and display all the payments including the new one in the view.

public function makepayment(Request $request)
    {
        

        $StudentPayment = SomasStudentPayment::create([
             'RegistrationID'=> $request->get('registrationid'),
             'PaymentTypeID' => $request->get('paymentTypeId'),
             'PaymentDate' => Carbon::now(),
             'CheckNum' => $request->get('checknum'),
             'PaymentAmount' => $request->get('paymentamount'),
           
         ]);
        

        $StudentPayments = SomasStudentPayment::where('RegistrationID','=', $request->get('registrationid'))
            ->join('somasstudentpaymenttype', 'somasstudentclasspayments.PaymentTypeID', '=', 'somasstudentpaymenttype.id')
            ->select('*', DB::raw('DATE_FORMAT(PaymentDate, "%m/%d/%Y") as PaymentDateF') , DB::raw('FORMAT(PaymentAmount, 2) as PaymentAmountF') )
            ->get();

             
        return json_encode($StudentPayments);

    }

What I would like to do is send additional data processed in the controller back the ajax, but separate the data out into separate variables ajax.

Adding these items to the controller. $PaymentsTotal = DB::table('somasstudentclasspayments')->where('RegistrationID', $request->get('registrationid'))->selectRaw('RegistrationID, sum(PaymentAmount) as TotalPayments')->groupBy('RegistrationID')->get(); $paymentTotal = (int)$PaymentsTotal[0]->TotalPayments;

    $TuitionTotal = $SOMASRegistration->ClassFee + $SOMASRegistration->HomeOfficeFee + $SOMASRegistration->MaterialsFee;
    
                
    $DueAmount = $TuitionTotal - $paymentTotal ;


return json_encode($StudentPayments, $PaymentsTotal, $TuitionTotal, $DueAmount );

Just like you would if you were just using returning the view with variables.

I can insert these variables into the array that's created but then I have to figure out how to separate all of it in javascript....

//$StudentPayments->put('PaymentTotal', $paymentTotal);

Is their a way to return multiple data variables back to the view where I can process the updates in the view with javascript? I hope I have given enough information.

15 Mar
6 days ago

jhutto left a reply on Insert Record From Ajax Post.

Thanks for all the support in trying to figure this out. As usual, it's the things that we can't see that get's us. After DavidLI post, I checked the fillable property. They were all there, but the PaymentType was actually a Payment TypeID... And then I realized, I'm trying to input text into a integer value. Just doesn't work.

Everything is working now. Sorry for the wild goose chase... but I wouldn't be able to stay with this without you. I love Laracasts.....

14 Mar
1 week ago

jhutto left a reply on Insert Record From Ajax Post.

Sorry... Everything is working except for the insert into database. It's failing and returning a server error.

I just can't get the data from the post inserted into the database.

jhutto started a new conversation Insert Record From Ajax Post.

I have tried everything I have read but I still can't insert a record from the ajax post response. I keeps giving me server error 500. I have confirmed that the ajax post call is working, because I can

I know the data is coming over because if I comment out the $input = request()->all(); and change the return to.... return json_encode($input); I get the json response back in the console. So, I know it's hitting the controller and responding.

I have tried inserting the data using this method... 'RegistrationID'=> = $request->input('registrationid');

Everything I tried gives me the server error which means that it didn't complete the tasks of inserting. I have also confirmed the line...

$StudentPayments = SomasStudentPayment::where('RegistrationID','=', 13939)->get(); is working because it returns all the payments for this record..

Please help... I'm pulling my hair out over this.... Thanks.

Here's my controller:

public function makepayment(Request $request)
    {
        //$input = request()->all();
        //$RegID = $request->input('registrationid');
       // $PaymentType = $request->input('paymentType');
       // $Checknum = $request->input('checknum');
       // $PaymentAmount = $request->input('paymentamount');

        $StudentPayment = new SomasStudentPayment([
                'RegistrationID'=> $request->get('registrationid'),
                'PaymentTypeID' => $request->get('paymentType'),
                'PaymentDate' => Carbon::now(),
                'CheckNum' => $request->get('checknum'),
                'PaymentAmount' => $request->get('paymentamount'),
          ]);
          $StudentPayment->save();

        

        $StudentPayments = SomasStudentPayment::where('RegistrationID','=', 13939)->get();

        
        return json_encode($StudentPayments);
    }

 $(document).ready(function(){
        $('#StudentPayment').submit(function (e) {
                e.preventDefault(); //**** to prevent normal form submission and page reload
               
               
                var $form_data = {};
                $form_data._token = $('meta[name="csrf-token"]').attr('content');
                $form_data.registrationid = $("input#RegID").val();
                $form_data.paymentType = $("select#PaymentType").val();
                $form_data.checknum = $("input#CheckNum").val();
                $form_data.paymentamount = $("input#PaymentAmount").val();
                
                console.log($form_data);
                
                $.ajax({
                        url: "/somaspayments/payment",
                        type: "POST",
                        dataType: 'json',
                        data: $form_data,
                        cache: false,
                        success: function (data) {
                                //alert('Your data updated');
                               
                                console.log(data);
                                //return data;
                            },
                            error: function () {
                                alert('error handing here');
                            }
                  });

                
                
        });
        });
21 Feb
1 month ago

jhutto left a reply on Cleaner Controllers

WOW... Great conversation. Thanks for all the input. I'm still new to this but you have given me plenty to researched and answered my question in several different ways. That's why I love this discussion area. You guys are great !

20 Feb
1 month ago

jhutto started a new conversation Cleaner Controllers

I recently watched the Laravel 5.7 From Scratch - Cleaner Controllers and Mass Assignment Concerns Video

And I started working on cleaning up my controllers. Then I ran into this one.

CHECKBOXES....

How do I get check boxes into this format......

Instructor::update(request(['FirstName', 'LastName']));

Here's my current update function (condensed of course)

$instructor = \App\Instructor::find($id);
        $instructor->FirstName = $request->FirstName;
        $instructor->LastName = $request->LastName;
        

        if (!$request->has('Viewable'))
        {
            // Checkbox is checked
            $instructor->Active = "0";
            
        }
        else
        {
             // Checkbox is not checked
             $instructor->Active = "1";
        }

                
        $instructor->save();

Thanks

11 Feb
1 month ago

jhutto started a new conversation Tabindex Using Laravel Collective Forms - Can't Find Anything

What am I missing but I can't find anything about tax indexing using Laravel Collective forms. Can anyone point me in the right direct? OR do I just use standard html forms?

04 Feb
1 month ago

jhutto started a new conversation Calling Functions Inside Same Controller

I'm working on a project which process credit cards. I have the separate credit card functions inside a controller and they work individually. They are post functions returning data and then a view.

But I need to setup a way to call them individually within the controller because I need to process an if case statement and return the $order data that is processed by the individual function and return the order information to the view.

I could make one very large function that processes a long if then else, but the function would get extremely long and hard to read. Any Help? Thanks.

public function process(Request $request)
{
    if ($request->paymenttype = 1) {
    process this credit card method function()  and return order information ($order)     
    $Order = Order::find($OrderID);

    }

    if ($request->paymenttype = 1) {
    process this credit card method function()  and return order information ($order)
    $Order = Order::find($OrderID);
    }


    if ($request->paymenttype = 1) {
    process this credit card method function()  and return order information ($order)   
    $Order = Order::find($OrderID);
    }

        

    return view('checkout.complete', compact('order'));
}
11 Jan
2 months ago

jhutto left a reply on Converting Mysql To Laravel Query

Perfect.. Thanks cemcminn... Yes.. I'm maintaining the database. I'm new to mysql.. so this is exactly what I needed.

jhutto left a reply on Converting Mysql To Laravel Query

I finally found some searches that lead me in the right direction.

$Registrations = DB::table('somascourseregistrations')
                ->select('somascourseregistrations.id', 'CourseID', 'TuitionType', 'FirstName', 'LastName',
                    DB::raw("(SELECT (ClassFee + HomeOfficeFee + MaterialsFee)                                
                                GROUP BY somascourseregistrations.id) as TotalTuition"),
                    DB::raw("(SELECT SUM(PaymentAmount) FROM somasstudentclasspayments
                                WHERE somasstudentclasspayments.RegistrationID = somascourseregistrations.id
                                GROUP BY somascourseregistrations.id) as TotalPayments"))
                ->join('students', 'students.id', '=', 'somascourseregistrations.StudentID')                
                ->where('CourseID', $courseid)
                ->orderby('LastName')
                ->get();

I'm still really new... But I will look at the stored procedures you are referring too. Can you give me some links to check out?

jhutto started a new conversation Converting Mysql To Laravel Query

I have a mysql query that I can not figure out how to translate into Laravel query in controller

The 355 will be a variable as soon as I can get this to run.

SELECT somascourseregistrations.id, `CourseID`, `StudentID`, `StatusID`, `TA`, `DropDate`, `TuitionType`, (`ClassFee`+`HomeOfficeFee`+`MaterialsFee`) AS TotalTuition,
(SELECT SUM(`PaymentAmount`) AS TotalPayments FROM `somasstudentclasspayments` WHERE somasstudentclasspayments.RegistrationID = somascourseregistrations.id) TotalPayments
FROM `somascourseregistrations` WHERE somascourseregistrations.CourseID = 355
10 Jan
2 months ago

jhutto started a new conversation Mysql Nested Query... How To Make It Work In Laravel Query

I've been trying to get this to work for quite awhile now and just need some help. I'm trying to write this query into a controller but can not figure out the format.

SELECT `CourseID`,`StudentID`, `ClassFee`,`HomeOfficeFee`,`MaterialsFee`, (`ClassFee`+`HomeOfficeFee`+`MaterialsFee`) AS TotalTuition, SUM(`PaymentAmount`)
FROM `somascourseregistrations`, `somasstudentclasspayments`
WHERE somascourseregistrations.id = somasstudentclasspayments.RegistrationID AND somascourseregistrations.id = $RegistrationID

Please help

23 Dec
2 months ago

jhutto left a reply on Can't Use The @ Sign In Javascript Code For Pulling Value

Thanks ahmeddabak, I finally resolved the issue with your help. Sorry for not explaining it better. This was a javascript issue, not laravel. It was an .ajax call that returned data and this issue was that way I tried to write the html table in javascript. All that I needed was to address the data correctly in javascript..

html += '<td>' + value['@id'] + '</td>';
html += '<td>' + value['firstName'] + ' ' + value['lastName'] + '</td>';

Thanks for you help. It did get me on the right track.

22 Dec
2 months ago

jhutto started a new conversation Can't Use The @ Sign In Javascript Code For Pulling Value

I'm working on a JavaScript code for an .ajax call to get data from an api application. Which is working ok but one of the values in the json data returned uses the @ as part of the index for the value. I can't seem to find a way to write the value.@id in a way that it will display in the view. Can any one explain to me why? I"m assuming the @ sign is a special character but I can't find anything that will give the special code value for the @ sign.

0:
@householdID: "1046330222"
@iCode: "7DFpn0vmmje4dA3bA9nNQQ=="
@id: "1075881761"
@imageURI: ""
@oldHouseholdID: ""
@oldID: ""
@uri: "https://milehi.staging.fellowshiponeapi.com/v1/People/1075881761"
addresses: {address: Array(2)}
firstName: "Jimmy"

When trying to display the data in a table, the @id comes back as not undefined

$.each(data, function(key, value) {
                        html += '<tr>';
                        html += '<td>' + [email protected] + '</td>';
                        html += '<td>' + value.firstName + ' ' + value.lastName + '</td>';

Thanks for any help on this.

20 Dec
3 months ago

jhutto left a reply on Add An Array Item To Collection Array In Controller

Thanks for your help guys... I probably didn't give you enough information. Sanpey... gave the idea I needed though, because I ended up just using the javascript code to add the values and display the total in the view. So, it's now working. Since it was using ajax call to the controller and returning json data, I parsed the json data to add the total.

totaltuitions = parseInt(value.ClassFee) + parseInt(value.MaterialsFee)+ parseInt(value.HomeOfficeFee);

I love the fact that when I need help, you guys respond so quickly to my questions. Even when I don't really know what I'm trying to do.

19 Dec
3 months ago

jhutto left a reply on Add An Array Item To Collection Array In Controller

Thanks for the quick reply. I'm using an ajax call on this item and need to return just one collection to a json. I then use that collection to layout the table in the view.

So, I need to add the item to the $Tuitions Collection. How do I add the TotalTuitions to the Tuitions collection?

jhutto started a new conversation Add An Array Item To Collection Array In Controller

I have three database fields that I need to add together and place in view. I'm using a ajax call to pull the data. I'm pulling the line of data from the database in the first collection that is created called Tuitions.

Then I"m adding the fields together in $TuitionTotal

Now I need to put the $TuitionTotal - Key 'TuitionTotal' and Value "140" back into the collection array[0] But I have not been able to find anything that works.

$Tuitions = Tuition::where('id', $id)->get();

$TuitionTotal = $Tuitions[0]->ClassFee + $Tuitions[0]->HomeOfficeFee + $Tuitions[0]->MaterialsFee ;
12 Dec
3 months ago

jhutto left a reply on Multiple Joins With Where's

Perfect... Sometimes we just get barrier in the code that we can't see the simple things. Like the wrong table and id. Thanks for your help.

jhutto started a new conversation Multiple Joins With Where's

I have a query that I can't get to work. It works if I take out the second join with instructors

$SemesterCourse = DB::table('coursesemester')
            ->join('somascourses', 'coursesemester.id', '=', 'somascourses.SemesterID')
            ->join('instructors', 'somascourses.SemesterID', '=', 'instructors.id')
            ->where([
                ['coursesemester.id', $semesterid],
                ['somascourses.id', $courseid],])
            ->get();

This mysql statement is working on the database

SELECT * FROM coursesemester
INNER JOIN somascourses ON coursesemester.id = somascourses.SemesterID
INNER JOIN instructors ON somascourses.Instructorid = instructors.id
WHERE coursesemester.id = 31 AND somascourses.id = 345

So, it seems to the the double Join that kills the query

11 Dec
3 months ago

jhutto left a reply on Adding Columns Of Row In Query Builder

That worded.. Thanks.

jhutto started a new conversation Adding Columns Of Row In Query Builder

I need to create a query to sum items in a row in query builder. Here is my current query in laravel

$SOMASRegistrations = \App\SOMASRegistration::where('CourseID', '=',  $course_id)
        ->join('somascourseregistrationstatus', 'somascourseregistrations.StatusID', '=', 'somascourseregistrationstatus.id')
        ->get();

I need to add three columns within the query and output as another column. Here is the mysql statement that works with the database

SELECT * , (ClassFee + HomeOfficeFee + MaterialsFee ) AS TotalFee FROM somascourseregistrations WHERE 1

I have tried this but it totals all the rows. I need the fields to be total only by each row.

$SOMASRegistrations = DB::table('somascourseregistrations') ->join('somascourseregistrationstatus', 'somascourseregistrations.StatusID', '=', 'somascourseregistrationstatus.id') ->select(DB::raw('sum(ClassFee+HomeOfficeFee+MaterialsFee) AS TotalFee')) ->where('CourseID', $course_id) ->get();

I couldn't find anything that talked about adding columns in a row in laravel Thanks for your help.

06 Dec
3 months ago

jhutto left a reply on Delete Confirmation In Form Button

Got it. Makes sense to me.

jhutto left a reply on Delete Confirmation In Form Button

If works fine. But I'm new to laravel and trying to learn the best way of doing things. So, that's why I posted this... Just wanted to make sure I wasn't missing something. Thanks for the response.

jhutto started a new conversation Delete Confirmation In Form Button

I have been working on a project and have a question about setting up a delete confirmation with the form. I can make it with a standard form

17 Oct
5 months ago

jhutto left a reply on Access Array Variable For Inserting Into Sql Table.

Thanks everyone for your help. This is the best for support.

jhutto left a reply on Access Array Variable For Inserting Into Sql Table.

$assistant['0']->NameCounter... Worked. Thanks for your help.

jhutto started a new conversation Access Array Variable For Inserting Into Sql Table.

I know this is a simple question and I should already know the answer but here it is....

I have an ajax call to a controller but I can't figure out how to access the array variable being created from a query call.

What am I doing wrong.. .And I know it's something simple.

This line is not getting inserted into the table. 'NameCounter' => $assistant->get('NameCounter'),

I have tried... 'NameCounter' => $assistant['NameCounter'], 'NameCounter' => $assistant['0']['NameCounter'],

 public function courseasstAjax($casstID, $courseID)
    {

             
        //Get NameCounter from Table of Course Assistants
        $assistant = DB::table('courseassistants')
        ->where('id', '=' , $casstID)
        ->get();
        
       
        //Create new record in SOMASCOURSEAssistants Table
        SOMASCourseAssistant::create([
             'ClassID' => $courseID,
              'NameCounter' => $assistant->get('NameCounter'),
          ]);
        
     
        
      return json_encode($assistant);

    

    }

I know the query is working because I can get it to return the array values in json....

[{…}]
0: {id: 7, NameCounter: 1649, FirstName: "Connie R", LastName: "Gabriel", Salutation: "Connie", …}
length: 1
__proto__: Array(0)
16 Oct
5 months ago

jhutto left a reply on Getting 500 (Internal Server Error) - When Sending Ajax Call To Controller

Thanks for the help... Cronix. I needed the logs to figure it out. It was an issue with the table name in the query that wasn't working correctly. It' working now. Thanks again.

jhutto started a new conversation Getting 500 (Internal Server Error) - When Sending Ajax Call To Controller

Getting 500 (Internal Server Error) - When sending ajax call to controller It's weird... .I'm using almost the exact same code in another page with not errors.

I have a drop down called courseassistants which has a list of names. I have a hidden input for the courseid.

 <label for="inputTA">Select Course Assistants to Add to Course: </label>
                            <input name="courseidnumber" id="courseidnumber" type="hidden" value="{{ $courseid  }}">
                            <select name="courseassistants" id="courseassistants" class="form-control">
                                <option value="">--- Select Assistant ---</option>
                                @foreach ($allassistants as $allassistant)
                                    <option value="{{ $allassistant->id }}">{{ $allassistant->FirstName }} {{ $allassistant->LastName }}</option>
                                @endforeach
                            </select>
                        </label>

Here's the ajax call:::

<script type="text/javascript">
$(document).ready(function() { 
    $('select[name="courseassistants"]').on('change', function() {
      var courseassistantID = $(this).val();
      var courseID = document.getElementById('courseidnumber').value;
      //var courseID = $('#courseidnumber').val();
      var html = '';
      $('#AssistantsTable').empty(); 
      console.log(courseassistantID, courseID);
      if(courseassistantID) {
                $.ajax({
                    url: '/courses/courseassistants/ajax/'+courseassistantID,
                    type: "GET",
                    dataType: "json",
                    success:function(data) {
                        
                        console.log(data);
                        html += '<table id="CoursesEdit" class="table table-striped table-bordered">';
                        html += '<thead><tr>';
                        html += '<th style="width: 10%"></th>';
                        html += '<th style="width: 30%">Course Name</th>';
                        html += '<th style="width: 20%">Instructor</th>';
                        html += '<th style="width: 10%">Day</th>';
                        html += '<th style="width: 10%">Time</th>';
                        html += '<th style="width: 10%"></th>';
                        html += '</tr></thead>';
                        
                        $.each(data, function(key, value) {
                            html += '<tr>';
                            html += '<td class="text-center"><a href="/courses/' + value.id + '/edit" id="btnRegistratios" class="btn btn-primary btn-lg" role="button">&nbsp; Registrations &nbsp;</a></td>';
                            html += '<td>' + value.ClassName + '</td>';
                            html += '<td>' + value.FirstName + ' '+ value.LastName + '</td>';
                            html += '<td>' + value.Day + '</td>';
                            html += '<td>' + value.Time + '</td>';
                            html += '<td class="text-center"><a href="/courses/' + value.SemesterID + '/' + value.course_id + '/edit" id="btnCourse" class="btn btn-primary btn-lg" role="button">&nbsp; Open &nbsp;</a></td>';
                           });
                        html += '</table>';
                        $('#coursesTable').append(html);
                       
                     
                    }
           
                });
                     
            }else{
                $('select[name="coursesTable"]').empty();
      }
      
  });
});
</script>

Here's the route:

Route::get('/courses/courseassistants/ajax/{casstID}',array('as'=>'courseasst.ajax','uses'=>'[email protected]'));

Controller function

 public function courseasstAjax($casstID, $ClassCourseID)
    {

        //dd($courseid);
        

        $coursesassistant = DB::table('coursesassistants')
        ->where('id', $casstID)
        ->get();
    

        return json_encode($coursesassistant);

     }

All I'm trying to do at this point is confirm everything is working, but I keep getting this error and no json data.

Please Help. Jimmy

29 Aug
6 months ago

jhutto left a reply on Creating Simple Dropdown From Database - Laravel Collective Form

That helped... Got some additional help and finalized it with this.... Thanks Croniz..

In Controller:

$instructors = DB::table('instructors')
            ->where('instructors.Viewable','=', 1)
            ->select(DB::raw('concat (FirstName," ",LastName) as FullName, id'));
            

$instructorOptions = array('' => 'Select Instructor') + $instructors->pluck('FullName', 'id')->toArray();

On View:

{{ Form::select('Instructors', $instructorOptions, null, ['class'=>'form-control']) }}

jhutto started a new conversation Creating Simple Dropdown From Database - Laravel Collective Form

I'm new to laravel and just trying to stay up to speed with the different versions. Using Laravel 5.6

I have created blade form and have been able to create my dropdown from the database,, but I keep running into forum questions showing selects using the Collective Form sytle. But I can't find anything in the documentation about the arguments for the {{ Form::Select ( arg1, arg2, arg3, arg4)}} ....... or how to create it from a database table.

So, I need help in writing this {{Form::Select }} statement that does the same thing as below.

Create Form ... Select looping through and creating the dropdown. Works good. Controller just pulls the list from database and passes it to the form as $instructors

<div class="form-group col-md-6">
                                                <label for="title">Instructor:</label>
                                                    <select name="Instructorid" id="Instructorid" class="form-control" style="width:350px;margin-left:50px;">
                                                        <option value="">--- Select Instuctor ---</option>
                                                        @foreach ($instructors as $instructor)
                                                            <option value="{{ $instructor->id }}">{{ $instructor->FirstName }} {{ $instructor->LastName }}"</option>">
                                                        @endforeach
                                                    </select>
                                                </label>
 </div>
``


How do I create the same loop in the {{ Form::select('Instructors', $instructors, ....) }} 
format?





17 Aug
7 months ago

jhutto started a new conversation Best Way To Process $request Data From Data Submitted On Form With Foreach Loop Table

What's the best way to take a table of data, show it on a form to edit using a foreach loop to create a table of input data. Then process it in the controller to update table in database.

To create the form I pull all the Tuition's from a db table that are associated with a Class ID.

$Tuitions = DB::table('tuitions')->where('ClassID','=', $coursesid)->get();

Then send it to the view.

Here's the form data creating a table of input in the view.

<div class="form-group col-md-12">
                                    <table id="Tuitions" class="table table-striped table-bordered">
                                            <thead><tr>
                                            <th style="width: 10%;text-align:center;">TuitionType</th>
                                            <th style="width: 30%;text-align:center;">TuitionDesc</th>
                                            <th style="width: 20%;text-align:center;">ClassFee</th>
                                            <th style="width: 20%;text-align:center;">HomeOfficeFee</th>
                                            <th style="width: 20%;text-align:center;">MaterialsFee</th>
                                            </tr></thead     
                                          
                                            @foreach ($Tuitions as $key=>$value)
                                            <tr>
                                                <input type="hidden" id="TuitionId" name="Tuitionid[]" value="{{ $value->id }}">
                                                <td><input type="text" id="TuitionType" name="TuitionType[]" style="text-align:center;"  value="{{ $value->TuitionType }}"></td>
                                                <td><input type="text" id="TuitionDesc" name="TuitionDesc[]"  style="width:350px" value="{{ $value->TuitionDesc }}"></td>
                                                <td><input type="text" id="ClassFee" name="ClassFee[]" style="text-align:center;" value="{{ $value->ClassFee }}"></td>
                                                <td><input type="text" id="HomeOfficeFee" name="HomeOfficeFee[]" style="text-align:center;" value="{{ $value->HomeOfficeFee }}"></td>
                                                <td><input type="text" id="MaterialsFee" name="MaterialsFee[]" style="text-align:center;" value="{{ $value->MaterialsFee }}"></td>
                                            @endforeach
                                              
                                              </label>
                                           
                                    </table>
                                </div>

Now here's the dd($request); The top portion of the request is data gathered in the same form that is class data. I have not problem pulling this information and updating it.

It's the data starting with Tuitionid... How do I extract this to update the tuitions table.

+request: ParameterBag {#64 ▼
    #parameters: array:15 [▼
      "_method" => "Patch"
      "_token" => "o6e8a4M2EnVsoUU4x87KbXtxFj1QXb9noiUjg3VG"
      "SemesterID" => "36"
      "Courseid" => "372"
      "ClassName" => "L&L Early Childhood"
      "instructor" => "10"
      "day" => "Thursday"
      "Time" => "6:30 PM"
      "Location" => "Vogt"
      "Tuitionid" => array:5 [▼
        0 => "4521"
        1 => "4522"
        2 => "4523"
        3 => "4524"
        4 => "4525"
      ]
      "TuitionType" => array:5 [▼
        0 => "SINGLE"
        1 => "COUPLE"
        2 => "S-STAFF"
        3 => "C-STAFF"
        4 => "GIFT"
      ]
      "TuitionDesc" => array:5 [▼
        0 => "Single"
        1 => "couple per person"
        2 => "single-staff"
        3 => "couple-staff"
        4 => "gift"
      ]
      "ClassFee" => array:5 [▼
        0 => "90.00"
        1 => "75.00"
        2 => "40.00"
        3 => "32.50"
        4 => "0.00"
      ]
      "HomeOfficeFee" => array:5 [▼
        0 => "0.00"
        1 => "0.00"
        2 => "0.00"
        3 => "0.00"
        4 => "0.00"
      ]
      "MaterialsFee" => array:5 [▼
        0 => "0.00"
        1 => "0.00"
        2 => "0.00"
        3 => "0.00"
        4 => "0.00"
      ]
    ]
  }

Anyone ?? Please help.

jhutto left a reply on Form Patch Submit Only Returning Last Record Of @foreach In Form

Thanks topvillas... That was it...

jhutto left a reply on Form Patch Submit Only Returning Last Record Of @foreach In Form

Sorry for the late response... Here's how I'm sending all the data to the form...

public function edittest($id, $coursesid)
    {
        
        

        $course = DB::table('somascourses')
            ->join('Instructors', 'somascourses.Instructorid', '=', 'Instructors.id')
            ->select('*','somascourses.id as course_id')
            ->where('somascourses.SemesterID','=','$id')
            ->orwhere('somascourses.id','=', $coursesid)
            ->get();
        
        //dd($course);

        $instructors = DB::table('instructors')->where('Viewable', '=', '1')->get();
        $semesterid = $id;
        $Courseid = $coursesid;

        $days = [
            'Sunday' => 'Sunday',
            'Monday' => 'Monday',
            'Tuesday' => 'Tuesday',
            'Wednesday' => 'Wednesday',
            'Thursday' => 'Thursday',
            'Friday' => 'Friday',
            'Saturday' => 'Saturday',
        ];

        $InstructorSelected = $course[0]->Instructorid;
       ($InstructorSelected);
       //dd($course);
       //dd($instructors);

       $Tuitions = DB::table('tuitions')->where('ClassID','=', $coursesid)->get();

       //dd($Tuitions);
      
       return view('courses.edittest', compact('course', 'instructors', 'semesterid', 'Courseid', 'days', 'InstructorSelected', 'Tuitions'));



    }

16 Aug
7 months ago

jhutto started a new conversation Form Patch Submit Only Returning Last Record Of @foreach In Form

I've create a edit form that is posting with patch method. I have a @foreach that creates the items in a table. When the form is submitted and I check the $request output it only returns the last entry from the @foreach loop. Can someone show me how to get all the values for each line item in the @foreach table

This is a simplified version of the form.

<!-- form user info -->
<div class="card card-outline-secondary">
<div class="card-header">
<h3 class="mb-0">Course Tuition</h3>
</div>
<div class="card-body">
 <form method="Post" action="/courses/{{ $Courseid }}" >
     @method('Patch')
     @csrf
                              
<div class="form-group col-md-12">
     <table id="Tuitions" class="table table-striped table-bordered">
               <thead><tr>
               <th style="width: 10%;text-align:center;">TuitionType</th>
               <th style="width: 30%;text-align:center;">TuitionDesc</th>
               <th style="width: 20%;text-align:center;">ClassFee</th>
               <th style="width: 20%;text-align:center;">HomeOfficeFee</th>
                <th style="width: 20%;text-align:center;">MaterialsFee</th>
                </tr></thead     
               @foreach ($Tuitions as $key=>$value)
                <tr>
        <td><input type="text" id="TuitionType" name="TuitionType" style="text-align:center;"  value="{{ $value->id }} {{ $value->TuitionType }}"></input></td>
            <td><input type="text" id="TuitionDesc" name="TuitionDesc"  style="width:350px" value="{{ $value->id }} {{ $value->TuitionDesc }}></td>
           <td><input type="text" id="ClassFee" name="ClassFee" style="text-align:center;" value="{{ $value->id }} {{ $value->ClassFee }}></td>
            <td><input type="text" id="HomeOfficeFee" name="HomeOfficeFee" style="text-align:center;" value="{{ $value->id }} {{ $value->HomeOfficeFee }}>/td>
            <td><input type="text" id="MaterialsFee" name="MaterialsFee" style="text-align:center;" value="{{ $value->id }} {{ $value->MaterialsFee }}></td>
                    @endforeach
              </table>
</div>
             <div class="form-row">
              <div class="form-group col-lg-9" Style="height:50px;margin-left: 25px;">
               <input type="submit" class="btn btn-primary btn-lg" value="Save Changes">
                  <a href="/registrations/courses/{{$course[0]->SemesterID}}" class="btn btn-secondary btn-lg" role="button">Cancel</a>
               </div>
</div>
</form>
                        
                        </div>
                    </div>

09 Aug
7 months ago

jhutto left a reply on Multiple Where Statements Not Working.

Sorry... It looks right but keep getting

syntax error, unexpected '}'

I've tried multiple variations.

jhutto started a new conversation Multiple Where Statements Not Working.

I'm passing multiple id's to a controller and trying to have it query the database. I have 3 tables that are linked in the query classsemester somascourses instructors

This mysql statement will retrieve the information from the database correctly. SELECT * FROM classsemester, somascourses, instructors WHERE classsemester.id = somascourses.SemesterID AND somascourses.Instructor_id = instructors.id AND classsemester.id = 2 AND somascourses.id = 2

Here's the function in the edit controller...

Since all the tables have a primary key of id.... I had to change the primary key for somascourses.id to course_id for it to show up in cc($course)l=; I need the to be able to put the starting table of classsemesters by the $id.. ID for that table and then pull the somascourses by a specific is using $courseid. Because I trying to pull a specific course from somascourses to edit.

 public function edit($id, $courseid)
    {
        
$course = DB::table('classsemester')
            ->join('somascourses', 'classsemester.id', '=', 'somascourses.SemesterID')    
            ->select('*','somascourses.id as course_id')
            ->join('Instructors', 'somascourses.Instructor_id', '=', 'Instructors.id')
            ->where('classsemester.id', '=', $id)
            ->orwhere('somascourses.SemesterID','=', $id)
            ->where('course_id', '=', $courseid)
            ->get();

}

How do I write this so, it will pull the same information as this mysql statement. SELECT * FROM classsemester, somascourses, instructors WHERE classsemester.id = somascourses.SemesterID AND somascourses.Instructor_id = instructors.id AND classsemester.id = 2 AND somascourses.id = 2

08 Aug
7 months ago

jhutto left a reply on Query That Has A Where Clause And With Clause.

Well .. I tried all of these but here's what worked..

$courses = \App\Course::where('SemesterID', $id)->join('Instructors', 'somascourses.Instructor_id', '=', 'Instructors.id')->get();

It returns all the fields from instructors table. I could not get any of the others to work and return the fields. I would love to be able to only return a few of the fields. Anyone????

07 Aug
7 months ago

jhutto left a reply on Query That Has A Where Clause And With Clause.

Got it.. Thanks... $courses = \App\Course::where('SemesterID', $id)->with('Instructor')->get(); This worked.

What about the other two questions???

jhutto started a new conversation Query That Has A Where Clause And With Clause.

I'm writing a ajax call to a controller with a function to return $courses I have two tables/Models... Courses and Instructors.

Instructor has...

public function Courses()
    {
        return $this->hasMany('App\Course');
    }

Courses has...
public function Instructor()
    {
        return $this->belongsTo('App\Instructor');
    }

I have a query that's working but would like to know how to write it the eloquent way...

This works. $courses = \App\Course::where('SemesterID', $id)->join('Instructors', 'somascourses.Instructor_id', '=', 'Instructors.id')->get();

This gives me an error not understanding the ::with..... //$courses = \App\Course::where('SemesterID', $id)::with('Instructor')->get();

Sorry... A couple of more questions.

  1. Should I be writing these as functions in the Model ? Or is it ok in the controller?

  2. How do I bring over only specific fields from the instructors table in the query?

30 Jul
7 months ago

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

Thank you so much. Great feed back. The code for the API was written by someone else, and I haven't made any modifications yet.. But your suggestions were right down the alley of where I wanted to go with it. But there code did a bunch of the heavy lifting to make the api easy to access. Again.. Great feed back and I really appreciate your time in helping me.

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

Here's the controller code

    public function searchName(Request $request)
    {

       
        $settings = array(
             setting code for API
        );
    

        $f1 = new FellowshipOne($settings);
        
        if(($r = $f1->login()) === false){
        die("Failed to loign");
        }

                
        $r = $f1->searchPeople(array(//search attributes
            "searchFor"=>$request['lastname'],
        ));
    
        
        
        return view('F1.index', compact('r')); 
        

    }

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

That worked... Thanks.. Seems simple now. Is there a better way to bring the data over to the view.

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

Here's the code in the view. Sorry about the original post.. I'm new to posting for support.

<table id="EditTables" class="table table-striped table-bordered">
     <thead>
       <tr>
       <th style="width: 10%">Id</th>
        <th style="width: 30%">Name</th>
        <th style="width: 50%">Address</th>
        <th style="width: 10%">Status</th>

        <th style="width: 20%">Select</th>
       </tr>
     </thead>
@if($r && $r['results']['@count']>0)
  
 @foreach($r['results']['person'] as $person)
   <tr>
  
   <td>{{$person['@id']}}</td>
   <td>{{$person['firstName']}} {{$person['lastName']}}</td>
   <td>{{$person['addresses']['address']['address1']}} </td>
   <td>{{$person['status']['name']}}</td>
   <td class="text-center"><a href="#" id="btnSelect" class="btn btn-primary btn-lg" role="button">&nbsp; Select &nbsp;</a></td>
   </tr>
@endforeach
  
@endif

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

array:1 [▼
  "results" => array:5 [▼
    "@count" => "2"
    "@pageNumber" => "1"
    "@totalRecords" => "2"
    "@additionalPages" => "0"
    "person" => array:2 [▼
      0 => array:40 [▼
        "@id" => "1075735630"
        "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075735630"
        "@imageURI" => ""
        "@oldID" => ""
        "@iCode" => "wo4QwInnbVOPIAc+XntOPg=="
        "@householdID" => "1046185397"
        "@oldHouseholdID" => ""
        "title" => null
        "salutation" => null
        "prefix" => null
        "firstName" => "Jack"
        "lastName" => "Siegman"
        "suffix" => null
        "middleName" => null
        "goesByName" => null
        "formerName" => null
        "gender" => null
        "dateOfBirth" => null
        "maritalStatus" => null
        "householdMemberType" => array:3 [▶]
        "isAuthorized" => "true"
        "status" => array:6 [▶]
        "occupation" => array:4 [▶]
        "employer" => null
        "school" => array:3 [▶]
        "denomination" => array:3 [▶]
        "formerChurch" => null
        "barCode" => null
        "memberEnvelopeCode" => null
        "defaultTagComment" => null
        "weblink" => array:3 [▶]
        "solicit" => null
        "thank" => "true"
        "firstRecord" => "2016-02-04T09:06:17"
        "attributes" => null
        "addresses" => array:1 [▶]
        "communications" => null
        "lastMatchDate" => null
        "createdDate" => "2016-02-04T09:06:18"
        "lastUpdatedDate" => "2016-02-04T09:06:22"
      ]
      1 => array:40 [▶]
    ]
  ]
]

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

[code]

array:1 [▼ "results" => array:5 [▼ "@count" => "2" "@pageNumber" => "1" "@totalRecords" => "2" "@additionalPages" => "0" "person" => array:2 [▼ 0 => array:40 [▼ "@id" => "1075735630" "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075735630" "@imageURI" => "" "@oldID" => "" "@iCode" => "wo4QwInnbVOPIAc+XntOPg==" "@householdID" => "1046185397" "@oldHouseholdID" => "" "title" => null "salutation" => null "prefix" => null "firstName" => "Jack" "lastName" => "Siegman" "suffix" => null "middleName" => null "goesByName" => null "formerName" => null "gender" => null "dateOfBirth" => null "maritalStatus" => null "householdMemberType" => array:3 [▶] "isAuthorized" => "true" "status" => array:6 [▶] "occupation" => array:4 [▶] "employer" => null "school" => array:3 [▶] "denomination" => array:3 [▶] "formerChurch" => null "barCode" => null "memberEnvelopeCode" => null "defaultTagComment" => null "weblink" => array:3 [▶] "solicit" => null "thank" => "true" "firstRecord" => "2016-02-04T09:06:17" "attributes" => null "addresses" => array:1 [▶] "communications" => null "lastMatchDate" => null "createdDate" => "2016-02-04T09:06:18" "lastUpdatedDate" => "2016-02-04T09:06:22" ] 1 => array:40 [▶] ] ] ]

[/code]

jhutto left a reply on Access Json Array Item Located At 3rd Level Down In The Array To Show In View

Sure.. Sorry.. Let me try again.

... array:1 [▼ "results" => array:5 [▼ "@count" => "2" "@pageNumber" => "1" "@totalRecords" => "2" "@additionalPages" => "0" "person" => array:2 [▼ 0 => array:40 [▼ "@id" => "1075735630" "@uri" => "https://milehi.staging.fellowshiponeapi.com/v1/People/1075735630" "@imageURI" => "" "@oldID" => "" "@iCode" => "wo4QwInnbVOPIAc+XntOPg==" "@householdID" => "1046185397" "@oldHouseholdID" => "" "title" => null "salutation" => null "prefix" => null "firstName" => "Jack" "lastName" => "Siegman" "suffix" => null "middleName" => null "goesByName" => null "formerName" => null "gender" => null "dateOfBirth" => null "maritalStatus" => null "householdMemberType" => array:3 [▶] "isAuthorized" => "true" "status" => array:6 [▶] "occupation" => array:4 [▶] "employer" => null "school" => array:3 [▶] "denomination" => array:3 [▶] "formerChurch" => null "barCode" => null "memberEnvelopeCode" => null "defaultTagComment" => null "weblink" => array:3 [▶] "solicit" => null "thank" => "true" "firstRecord" => "2016-02-04T09:06:17" "attributes" => null "addresses" => array:1 [▶] "communications" => null "lastMatchDate" => null "createdDate" => "2016-02-04T09:06:18" "lastUpdatedDate" => "2016-02-04T09:06:22" ] 1 => array:40 [▶] ] ] ] ...

...

Id Name Address Status
    <th style="width: 20%">Select</th>
   </tr>
 </thead>

@if($r && $r['results']['@count']>0)

@foreach($r['results']['person'] as $person)

{{$person['@id']}} {{$person['firstName']}} {{$person['lastName']}} {{$person['addresses']['address']['address1']}} {{$person['status']['name']}}   Select   @endforeach

@endif ...