bobmyles

bobmyles

Member Since 2 Years Ago

Experience Points 2,740
Experience Level 1

2,260 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 18
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.

20 Mar
3 months ago

bobmyles started a new conversation Laravel's Localization On JavaScript Variables

I have some JavaScript variables that I output on a rating scale as shown below.

I now want to achieve Laravel's localization therefore translate the variables before outputting them on the browser.

How can I achieve this? I tried as below but it does not get converted.

var ratingScale = {1: 'Terrible, 2: 'Poor', 3: 'Average', 4: 'Good', 5: 'Excellent'}; 

I would want to Localize the variables Terrible, Poor, Average, Good, and Excellent.

I tried this

var one = "<?php echo trans('form.one'); ?>";
     
var ratingScale = {1: one, 2: 'Poor', 3: 'Average', 4: 'Good', 5: 'Excellent'};

But on the browser this is outputted <?php echo trans('form.one'); ?>

Anyone lead me here?

11 Mar
3 months ago

bobmyles started a new conversation Writing A SQL Query Into Eloquent

I have a query as below, I am struggling to write it into Eloquent,

SELECT id, description FROM turnovers ORDER BY CASE WHEN id = (SELECT MAX(id) FROM turnovers) THEN 0 ELSE 1 END, id;

The model is Turnover.

Any help is appreciated.

27 Feb
3 months ago

bobmyles started a new conversation Getting Data From Multiple Tables Via Laravel Eloquent

I have three tables; rate_params, review_form_languages, and review_form_translations. And corresponding models RateParam, ReviewFormLanguage and reviewFormTranslation.

rate_params has columns id, info_message, order and validation.

review_form_languages has id and name

review_form_translations has id, rate_params_id, review_form_languages_id, and text.

I would like to have query that fetches all the data from rate_params and the text from review_form_translations where review_form_languages.name is the passed parameter.

I have a query that fetches all the data from RateParam model as below

 $reviewForm = RateParam::select(
        'rate_params.id',
        'rate_params.validation',
        'rate_params.info_message',
    )->orderBy('order', 'asc')->get()->toArray();
    

How do I join to get the text from review_form_translations where review_form_languages.name is the passed parameter?

11 Feb
4 months ago

bobmyles started a new conversation Found 2 Elements With Non-unique Id. Loading The Selected Div Only To Avoid Conflict

I have an option select tag where a user picks the option they want on a drop down.

<div class="button dropdown"> 
  <select id="languageselector">
     <option value="english">English</option>
     <option value="swahili">Swahili</option>
  </select>
</div>

I have noted since I am reusing the same ids, it's failing and giving warnings [DOM] Found 2 elements with non-unique id. The first option loads well but the second option fails to load correctly giving [DOM] Found 2 elements with non-unique id.

Is there a way to disable one based on the selection because I think both are loading the same time hence the conflict?

<div class="button dropdown"> 
  <select id="languageselector">
     <option value="english">English</option>
     <option value="swahili">Swahili</option>
  </select>
</div>

 <div id="english" class="language english">
        <form id="reviewForm" method="POST" action="/review/post">
        <div id="reviewFormPage">
        {!! csrf_field() !!}
        {!! Form::hidden('business_name', $provider->businessId, ['class'=>'form-control', 'id' => 'businessId']) !!}
        {!! Form::hidden('acceptTerms', null, ['class'=>'form-control', 'id' => 'acceptTerms']) !!}
            <div class="row">
                <div class="col-xs-12">
                    <div class="checkbox icheck">
                        <label>
                        {!! Form::checkbox('existing_customer', '1', false, ['id' => 'existing_customer_review']) !!}
                            I am an existing customer.
                        </label>
                    </div>
                </div>
            </div>
       </form>
 </div>


 <div id="swahili" class="language swahili">
        <form id="reviewForm" method="POST" action="/review/post">
        <div id="reviewFormPage">
        {!! csrf_field() !!}
        {!! Form::hidden('business_name', $provider->businessId, ['class'=>'form-control', 'id' => 'businessId']) !!}
        {!! Form::hidden('acceptTerms', null, ['class'=>'form-control', 'id' => 'acceptTerms']) !!}
            <div class="row">
                <div class="col-xs-12">
                    <div class="checkbox icheck">
                        <label>
                        {!! Form::checkbox('existing_customer', '1', false, ['id' => 'existing_customer_review']) !!}
                            Mimi ni mteja anayerudi.
                        </label>
                    </div>
                </div>
            </div>
       </form>
 </div>

The JavaScript code is as below;

<script type="text/javascript">
    $(function() {
      $('#languageselector').change(function(){
        $('.language').hide();
        $('#' + $(this).val()).show();
      });
    });
</script>

bobmyles started a new conversation How To Get The Ajax Response From Controller To A PHP Variable On The View

I am making an ajax request to the controller as shown below;

   <script>    
    $(function() {
    // when select changes
        $('#languageselector').on('change', function() {
            // create data from form input(s)
            let formData = $('#myForm').serialize();
            // send data to your endpoint
            $.ajax({
                url: '/selected/languageId',
                method: 'post',
                data: formData,
                dataType: 'json', // we expect a json response
                success: function(response) {
                    // whatever you want to do here. Let's console.log the response
                    console.log(response); 
                }
            });
        });
    });
  </script>

On the controller, I am returning

public function selectedLangId(Request $request)
{
    return response()->json(['success'=> $request->languageSelected]);
}

I would like to get this JSON response json(['success'=> $request->languageSelected]) and assign it to a PHP variable on the view.

How do I manage that?

From the logs, the response is in the form of {"success":"2"}

I would want to get this JSON response and save it into a PHP variable on the view....

I want to use this variable to display certain forms according to this selection.

10 Feb
4 months ago

bobmyles left a reply on How To Get The HTML Select Option In AJAX

@CRONIX - Hi @cronix your way of doing it works well... The request hits the controller.. Works as expected!

Quick question, on the view with the form myForm how do I get back the languageSelected passed to controller to reuse on that view?

bobmyles left a reply on How To Get The HTML Select Option In AJAX

@CRONIX - Hello @cronix I did test with your set up but still the page reloads... I changed the url to test if the AJax request was hitting the URL or if I was getting a 404. But still nothing

bobmyles started a new conversation How To Get The HTML Select Option In AJAX

On a dropdown option, I would like to listen in and get the value of the option selected by the user.

Then I would like to pass this value to a PHP variable for use in the later part of the blade view PHP script.

I do not want to reload the page hence from the online look, I found ajax to be the only possible way.

I tried to implement as shown below but hitting a snag as the page loads on submit.

Even better is it possible to have a select option drop down that you get the selected value without submit?

My HTML code:

<form id="myForm">
    <div class="button dropdown">
      <select name="languageSelected" required="required" id="languageselector">
        <option value="">Select the language</option>
        @foreach($reviewForm_language as $lang)
         <option value="{{$lang->id}}">{{$lang->name}}</option>
        @endforeach
      </select>
      
    </div>
    <input id="ajaxSubmit" type="submit" value="Select"/>
  </form>

The JavaScript code:

  <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="

crossorigin="anonymous">

<script>    
jQuery('#languageselector').on('change', function(){      

    jQuery.ajax({
      url: "{{ url('/selected/id') }}",
      method: 'post',
      data: {
         id: $(this).val(),
      },
      success: function(result){
         jQuery('.alert').show();
         jQuery('.alert').html(result.success);
      }
    });

});

The PHP code to pick the selected language id

<?php
  $langId = request()->get('languageSelected');
?>

My route code;

Route::post('/selected/languageId', '[email protected]');

My controller Code;

public function selectedLangId(Request $request)
{
    return response()->json(['success'=> $request->id]);
}

I am learning AJAX, and for some reasons the page loads. Anyone kindly guide me?

bobmyles left a reply on Ajax Call To Get The Value Selected From A HTML Select Option

@snapey oh, the function was used just to test that I can get the value... Please ignore it.

bobmyles started a new conversation Ajax Call To Get The Value Selected From A HTML Select Option

On a dropdown option, I would like to listen in and get the value of the option selected by the user.

Then I would like to pass this value to a PHP variable for use in the later part of the blade view PHP script.

I do not want to reload the page hence from the online look, I found ajax to be the only possible way.

I tried to implement as shown below but hitting a snag as the page loads on submit.

Even better is it possible to have a select option drop down that you get the selected value without submit?

My select option code:

Pick A language @foreach($reviewForm_language as $lang) {{$lang->name}} @endforeach

My JS code:

jQuery(document).ready(function(){ jQuery('#ajaxSubmit').click(function(e){ e.preventDefault(); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content') } }); jQuery.ajax({ url: "{{ url('#') }}", method: 'post', data: { id: jQuery('#languageSelected').val(),
          },
          success: function(result){
             jQuery('.alert').show();
             jQuery('.alert').html(result.success);
          }});
       });
    });

On reload I can get the value as a GET request as below; however, I do not want to reload the page but for some reasons it does reload.

<?php
    $langId = request()->get('languageSelected');
 ?>

Anyone?

18 Sep
1 year ago

bobmyles started a new conversation Parsing Soap Response In PHP

I am new in Soap Web Services. I am trying to get the values from a soap request;

<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Body> <c2b:C2BPaymentValidationRequest xmlns:c2b="http://cps.huawei.com/cpsinterface/c2bpayment"> <TransID>3IN40005PY</TransID> <TransTime>20160923143639</TransTime> <TransAmount>3000</TransAmount> <BusinessShortCode>10069</BusinessShortCode> <MSISDN>86812530102</MSISDN> <KYCInfo> <KYCName>FirstName</KYCName> <KYCValue>aaa</KYCValue> </KYCInfo> <KYCInfo> <KYCName>MiddleName</KYCName> <KYCValue>bbb</KYCValue> </KYCInfo> <KYCInfo> <KYCName>LastName</KYCName> <KYCValue>ccc</KYCValue> </KYCInfo> </c2b:C2BPaymentValidationRequest> </soapenv:Body> </soapenv:Envelope>

I tried making an object

`$xml=simplexml_load_string($response) or die("Error: Cannot create object");`

So that I can read the values as below;

`$TransID=$xml->TransID; `
`$TransTime=$xml->TransTime; `
`$TransAmount=$xml->TransAmount;`

But it fails here die("Error: Cannot create object");

Or even better how can I change the soap request to json and get the values? Anyone?

05 Jul
1 year ago

bobmyles left a reply on Join Statement Using Query Builder

I figured it out as below;

$content = DB::table('subscribed_services as a')
    ->join('scheduled_messages as b', 'a.id', '=', 'b.subscribed_services_id')
    ->join('subscription_services_msisdn as c', 'a.id', '=', 'c.subscribed_services_id')
    ->whereRaw('DATE(b.scheduled_at) = CURDATE()')
    ->whereRaw('DATE(c.sent_time) <> CURDATE()')
    ->selectRaw('b.message, c. phone_number, a.username, a.password')
    ->distinct()
    ->get();

bobmyles started a new conversation Join Statement Using Query Builder

Hi there,

I have a Query builder statement below and I would want to introduce another condition to the query. However, I can not get this right.

This query works fine;

$content = DB::table('subscribed_services as a')
                ->join('scheduled_messages as b', 'a.id', '=', 'b.subscribed_services_id')
                ->join('subscription_services_msisdn as c', 'a.id', '=', 'c.subscribed_services_id')
                ->whereRaw('DATE(b.scheduled_at) = CURDATE()')
                ->selectRaw('b.message, c. phone_number, a.username, a.password')
                ->distinct()
                ->get();

I would want to introduce another where statement; this ->whereRaw('DATE(c.sent_time) != CURDATE()'). Meaning the query above should only pick values where subscription_services_msisdn.sent_time DATE(c.sent_time) IS NOT EQUAL to Current Date CURDATE().

Anyone lead me here. Regards.

04 Jul
1 year ago

bobmyles left a reply on Converting Join Sql Statement To Eloquent.

Thank you tykus... Let try and convert it using query builder.

bobmyles started a new conversation Converting Join Sql Statement To Eloquent.

I have three models.

  1. ScheduledMessage points to table scheduled_messages.
  2. SubscribedService points to table subscribed_services.
  3. SubscriptionServicesMsisdn points to table subscription_services_msisdn.

I have raw sql query that I would want to convert into eloquent but can not think of a way.

SQL Query:

SELECT DISTINCT 
  b.message, c. phone_number, a.username, a.password from subscribed_services a 
inner join 
  subscription_services_msisdn c on a.id = c.subscribed_services_id 
inner join 
 scheduled_messages b on a.id = b.subscribed_services_id where DATE(b.scheduled_at) = CURDATE()

Would someone please help convert to eloquent. Thank you.

27 Apr
2 years ago

bobmyles left a reply on How To Upload An Image And Display As Logo

This is how I was able to achieve this, well just in case some one else is struggling.

I changed my default disk on the file system to public i.e. (`app/config/filesystem.php)

Then created a symbolic link app/storage/app/public to app/public/storage

This enabled me to access all files on app/public/storage ....

To access the logos on the view I used img src="APP_URL/public/storage/logos/logo.png"

Thank you guys for the assistance .... About this and more here => https://laravel.com/docs/5.4/filesystem#the-public-disk

21 Apr
2 years ago

bobmyles left a reply on How To Upload An Image And Display As Logo

Below is the abs path to the image;

<span class="logo-lg"><img src="/var/www/html/airtime_top_up_portal/storage/app/public/logos/bobChild/logo.png" class="img-responsive" ></span>
    </a>

Is this what you need?

bobmyles left a reply on How To Upload An Image And Display As Logo

I have tried this but failed;

bobmyles left a reply on How To Upload An Image And Display As Logo

Hi... I tried php artisan storage:linkbut got;

I went though the doc as well.

[ErrorException] symlink(): No such file or directory

I am on ubuntu os ..

Kindly advice

bobmyles left a reply on How To Upload An Image And Display As Logo

Hi Robert, I changed the Default Filesystem Disk to use public ....

This created storage/app/public/logos/bobChild storage path..

The images are stored on the path storage/app/public/logos/bobChild/logo.png How do I create the symboilc link?

Kindly advice.

bobmyles left a reply on How To Upload An Image And Display As Logo

I tried this

<span class="logo-lg"><img src="Storage::local('app/logos/Demo/logo.jpg');" class="img-responsive" ></span>

this as well;

<span class="logo-lg"><img src="storage_path('app/logos/Abc/logo.jpg')" class="img-responsive" ></span>

but there was no display

bobmyles left a reply on How To Upload An Image And Display As Logo

@edoc You mean this? <img src="storage_path('logos/Demo/logo.jpg')"

bobmyles started a new conversation How To Upload An Image And Display As Logo

I am using Laravel 5.4. I am creating organizations; whose details include a logo.

The intention is when a user for the organization logs in, the logo is on the display.

I am able to upload and save the logo on storage/app/logos/organization_name/logo... eg storage/logos/Abc/logo.jpg

However, I am not able to pick and display the image/logo for an organization. I have gone through the docs https://laravel.com/docs/5.3/requests#retrieving-uploaded-files but still struggling.

Kindly someone save my day.

Image Upload and save code below: $org_image = $request->org_image;

        if ($org_image !== null) {
            $fileext = $org_image->getClientOriginalExtension(); //Get file extension
            $org_image->storeAs('logos/' . $organization_name, "logo.{$fileext}"); //save file 
     
         }

How do I fetch and display this on the view diffentiating by the organization name?

Regards.

29 Mar
2 years ago

bobmyles left a reply on Trait 'Illuminate\Database\Concerns\BuildsQueries' Not Found

Sorry I can not explain why but here is the fix

FIX

1. I deleted /vendor with all it's files
2. composer install
3. It worked. 

I am not sure but I think git ignored /vendor on gitignore all along?

Regards.

bobmyles started a new conversation Trait 'Illuminate\Database\Concerns\BuildsQueries' Not Found

Laravel Version: 5.4.* PHP Version: 7.0.17 Database Driver & Version: Ver 14.14 Distrib 5.5.54, for debian-linux-gnu (x86_64) using readline 6.3 Description:

I am trying to login to my platform but getting this error, Trait 'Illuminate\Database\Concerns\BuildsQueries' not found

I have not done any changes on the file /vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:23 as from the logs the exception is; local.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Trait 'Illuminate\Database\Concerns\BuildsQueries' not found in /var/www/html/project_name/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:23 Stack trace: #0 {main}

I can not interpret any further as that is the information I get from the logs.

Kindly someone advice.

Regards. Bob Mwenda.

Steps To Reproduce:

I tried submitting my login form; then got the error FatalErrorException in Builder.php line 23: Trait 'Illuminate\Database\Concerns\BuildsQueries' not found on the screen.

I can not figure out how to solve this.

09 Feb
2 years ago

bobmyles left a reply on How Do I Change The Default Register And Login Controllers In Laravel 5.3?

So, when I get rid of use AuthenticatesUsers; on Login Controller, I get Method App\Http\Controllers\Auth\LoginController::login() does not exist

Does this mean I will have to create manual routes for the application?

Kindly advice.

bobmyles started a new conversation How Do I Change The Default Register And Login Controllers In Laravel 5.3?

I would want to have this scenario that when a user signs up, an activation token is generated and sent to the email address specified.

On the users table, I have $table->boolean('is_activated')->default(0); that should be updated to 1 if the email link is clicked by the user. Hence the user is able to login as by the login controller below.