uhbc

uhbc

Member Since 1 Year Ago

Experience Points
1,590
Total
Experience

3,410 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
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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
1,590 XP
Aug
26
1 month ago
Activity icon

Replied to Validate If A String Has Letters

No characters othert than numbers, spaces and parantheses

Activity icon

Replied to Validate If A String Has Letters

$request->validate([
'phone' => 'regex: /^0\s\(?\d{3}\)?\s\d{3}\s\d{4}$/'
], [
'phone.regex' => 'Phone number format is incorrect.'
]);

Didn't throw any error at all.

Activity icon

Started a new Conversation Validate If A String Has Letters

Hi, Here is what I use for validating the form

// Allowed formats: 
// 0 (xxx) yyy zzzz
// 0 xxx yyy zzzz
$request->validate([
'phone' => 'regex: ?'
], [
'phone.regex' => 'Phone number format is incorrect.'
]);

I wanna throw an error If someone passes letters with form. How do I handle this with or without regex?

Jul
13
3 months ago
Activity icon

Started a new Conversation Changing Locale Causes Problem With Session

Here is the Locale.php middleware:

<?php

namespace App\Http\Middleware;

use Closure;
use Session;
use Config;
use App;
class Locale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
      $locale = Session::get('locale', Config::get('app.locale'));
      App::setLocale($locale);
      
      return $next($request);
    }
}


And kernel.php includes:

    protected $middleware = [
        \App\Http\Middleware\CheckForMaintenanceMode::class,
        \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
        \App\Http\Middleware\TrimStrings::class,
        \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
        \App\Http\Middleware\TrustProxies::class,
        \Illuminate\Session\Middleware\StartSession::class,  #<<<-- This causes the problem on catching Session values..
        \App\Http\Middleware\Locale::class,
    ];

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:60,1',
            'bindings',
        ],
    ];

Web.php :

Route::get('/langs/{lang?}', '[email protected]')->name('setLang');

LanguageController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Session;
use App;
use Redirect;
use App\TranslatorModel;
class LanguageController extends Controller
{
  
  public function setLang($lang){
    if (!in_array($lang, [ 'en', 'ru', 'su', 'de', 'fr'])) {
      $lang = 'en';
    }
    Session::put('locale', $lang);
    return back();
  }
}

The problem is when I'm enabling the StartSession::class in kernel.php -> $middleware[ ] Changing locale works fine but I'm not being able to catch Session data, such as Session::get('message'); etc.

When I'm disabling it, there's no problem with getting Session data but now I can't change the locale. How do I get out of this trouble?

Jun
06
4 months ago
Activity icon

Replied to How To Return Multiple Variables To A View And Use Them

Thank you @sergiu17 @cronix I decided to create a new view. Things are less complicated now.

Jun
05
4 months ago
Activity icon

Started a new Conversation How To Return Multiple Variables To A View And Use Them

How do I use multiple variables that are returned by different functions in the controller. Please take a look at the codes to understand what I exactly mean.

Here is the controller:

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use App\User;
class HomeController extends Controller
{

    public function function1(){
      // https://site.com/home
      $res = \DB::table("somedb")->get();
      return view('home', ["variable1"=>$res]);
    }
    public function function2($id){
      // https://site.com/home/1
      $res = \DB::table("somedb")->where("id", $id)->get();
      return view('home', ["variable2"=>$res]);
    }

}


And here is the home.blade.php


<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>ID</th>
          <th>Name</th>
          <th>Process</th>
        </tr>
      </thead>

      @if(isset($variable1))
      <tbody>
        @foreach($variable1 as $row)
        <tr>
          <td>{{$row->id}}</td>
          <td>{{$row->name}}</td>
          <td>[a button to edit this row etc..]</td>
        </tr>
        @endforeach
    </tbody>
    @else
      <tbody>
        @foreach($variable2 as $row)
        <tr>
          <td>{{$row->id}}</td>
          <td><input type="text" name="name" value="{{$row->name}}"></td>
          <td>[a button to submit etc..]</td>
        </tr>
        @endforeach
      </tbody>
    @endif
    </table>
  </body>
</html>

When I'm trying to this, giving me an error of "Undefined variable: variable2 (View: .../home.blade.php)"

The reason i wanna do this is that i dont wanna create another view.

What should I do