grozavule

grozavule

Member Since 6 Months Ago

Experience Points
4,480
Total
Experience

520 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
39
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
4,480 XP
Sep
16
1 week ago
Activity icon

Started a new Conversation Applying Additional Form Validation Rules To Selectively Required Fields

I have a form that only requires that one field be complete; it doesn't matter which one. If the field has a value, I would like that value to meet other criteria. Here is the form:

<form action="{{ route('reports.customerordersearch') }}" method="get">
                <div class="form-group">
                    <label class="form-label" for="customer_id">CUSTOMER:</label>
                    @error('customer_id')
                    <div class="alert alert-danger" role="alert">{{ $message }}</div>
                    @enderror
                    <select class="custom-select" name="customer_id">
                        <option value="" selected>Select a customer</option>
                        @foreach($customers as $customer)
                        <option value="{{ $customer->ID }}">{{ $customer->NAME }}</option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label class="form-label" for="order-number">CUSTOMER ORDER NUMBER:</label>
                    @error('order-number')
                    <div class="alert alert-danger" role="alert">{{ $message }}</div>
                    @enderror
                    <input type="text" name="order_number" class="form-control{{ $errors->has('order-number') ? ' is-invalid' : ''}}" value="{{ old('order-number') }}" placeholder="Enter a customer order number to search for" />
                </div>
                <div class="form-group">
                    <label class="form-label" for="order_status">ORDER STATUS:</label>
                    @error('order_status')
                    <div class="alert alert-danger" role="alert">{{ $message }}</div>
                    @enderror
                    <select class="custom-select" name="order_status">
                        <option value="U" selected>Select an order status</option>
                        <option value="R">Released</option>
                        <option value="C">Closed</option>
                        <option value="H">On hold</option>
                        <option value="X">Cancelled/Void</option>
                    </select>
                </div>
                <input class="btn btn-primary" type="submit" name="submit" value="Search" />
                @csrf
            </form>

Here are the validation requirements:

$validStatuses = array_keys(self::CUSTOMER_ORDER_STATUS);
            $validInput = $request->validate([
                'customer_id' => ['bail', 'required_without_all:order_number,order_status', 'alpha_num'],
                'order_number' => ['bail', 'required_without_all:customer_id,order_status', 'string'],
                'order_status' => ['bail', 'required_without_all:order_number,customer_id', Rule::in($validStatuses)]
            ]);

If I only fill out Order Status, the Customer field complains that its value, which is intentionally left blank, is not alphanumeric. I would like its alphanumeric requirement to only apply if the field has a value. How can I do that?

Activity icon

Awarded Best Reply on Conditional Where Clauses Using Query Builder

Thanks for your input. I had my variables in an Eloquent collection already. After tinkering with the code, I think I found the solution:

$variableRevision = DB::connection('engineering')
                ->table('VariableValue as vv')
                ->join('Documents as d', 'd.DocumentID', '=', 'vv.DocumentID')
                ->select('VariableID', DB::raw('max(RevisionNo) as MaxRevisionNo'))
                ->where('d.Filename', '=', $this->partNumber . self::SOLIDWORKS_PART_FILE_EXTENSION)
                ->whereIn('vv.VariableID', self::PDM_VARIABLES)
                ->groupBy('vv.VariableID')
                ->get();

            $variableValues = DB::connection('engineering')
                ->table('VariableValue as vv')
                ->join('Variable as v', 'v.VariableID', '=', 'vv.VariableID')
                ->join('Documents as d', 'd.DocumentID', '=', 'vv.DocumentID')
                ->select('v.VariableName', 'vv.ValueText')
                ->where('d.Filename', '=', $this->partNumber . self::SOLIDWORKS_PART_FILE_EXTENSION);

            if($variableRevision->count() > 0)
            {
                $variableValues->where(function($query) use ($variableRevision, $variableValues){
                    $variableRevision->each(function($item, $key) use ($query, $variableValues){
                        $query->orWhere(function($q) use($item){
                           $q->where('vv.VariableID', '=', $item->VariableID)
                               ->where('vv.RevisionNo', '=', $item->MaxRevisionNo);
                        });
                    });
                });
            }
            $values = $variableValues->get();
Sep
12
2 weeks ago
Activity icon

Replied to Form Validation

@lemmon This worked! Thanks for your help.

Sep
11
2 weeks ago
Activity icon

Replied to Form Validation

I apologize for not explaining what I needed better. I need the form to only complain if part-number, part-description, and part-category are empty. If any one of those three fields are filled, the form should submit without complaint. Does that make more sense?

Activity icon

Replied to Form Validation

Ismaile,

Thanks for weighing in. I tried your solution, and the validation still fails if part-number or part-description are empty.

Activity icon

Started a new Conversation Form Validation

I have three fields in a form. Only one of them needs to be filled out for the form to submit. Whenever only the radio button field is selected, the validation triggers an error on the two input fields for not being completed.

Here is the form:

<form action="{{ route('reports.partsearch') }}" method="get">
    <div class="form-group">
        <label class="form-label" for="part-number">PART NUMBER:</label>
        @error('part-number')
        <div class="alert alert-danger" role="alert">{{ $message }}</div>
        @enderror
        <input type="text" name="part-number" class="form-control{{ $errors->has('part-number') ? ' is-invalid' : ''}}" value="{{ old('part-number') }}" placeholder="Enter a part number to search for" />
    </div>
    <div class="form-group">
        <label class="form-label" for="part-description">DESCRIPTION:</label>
        @error('part-description')
        <div class="alert alert-danger" role="alert">{{ $message }}</div>
        @enderror
        <input type="text" name="part-description" class="form-control{{ $errors->has('part-number') ? ' is-invalid' : ''}}" value="{{ old('part-description') }}" placeholder="Enter a part description to search for" />
    </div>
    <div class="form-group">
        <label for="part-category">PART CATEGORY:</label>
        <div class="form-check">
            <input name="part-category" class="form-check-input" type="radio" value="PP" id="part-category-pp" {{ (old('part-category') === 'PP') ? 'checked' : '' }}/>
            <label class="form-check-label" for="part-category-pp">Purchased Parts</label>
        </div>
        <div class="form-check">
            <input name="part-category" class="form-check-input" type="radio" value="MP" id="part-category-mp" {{ (old('part-category') === 'MP') ? 'checked' : '' }}/>
            <label class="form-check-label" for="part-category-mp">Manufactured Parts</label>
        </div>
        <div class="form-check">
            <input name="part-category" class="form-check-input" type="radio" value="BOTH" id="part-category-mp" {{ (old('part-category') === 'BOTH') ? 'checked' : '' }}/>
            <label class="form-check-label" for="part-category-mp">Both</label>
        </div>
    </div>
    <input class="btn btn-primary" type="submit" name="submit" value="Search" />
</form>

Here are my validation rules:

$validInput = $request->validate([
    'part-number' => ['bail', 'required_without_all:part-description, part-category', 'string'],
    'part-description' => ['bail', 'required_without_all:part-number, part-category', 'string'],
    'part-category' => [Rule::in(['MP', 'PP', 'BOTH'])]
]);

Can anyone tell me what I'm doing wrong? Thanks.

Sep
08
2 weeks ago
Activity icon

Started a new Conversation Use Query Builder To Select From Two Subqueries

I'm at a loss on how to duplicate the following query using the query builder:

select ii.total_in, io.total_out, (ii.total_in - io.total_out) as QTY_ON_HAND, ii.warehouse_id, ii.part_id 
from (select sum(it.qty) as total_in, it.warehouse_id, it.part_id from INVENTORY_TRANS it join PART_SITE ps on it.PART_ID=ps.PART_ID where it.type='I' and it.PART_ID = '46277' and it.TRANSACTION_DATE <= '2019-01-01' and ps.SITE_ID='AF' group by it.WAREHOUSE_ID, it.PART_ID) as ii
join (select sum(it.qty) as total_out, it.warehouse_id, it.part_id from INVENTORY_TRANS it join PART_SITE ps on it.PART_ID=ps.PART_ID where it.type='O' and it.PART_ID = '46277' and it.TRANSACTION_DATE <= '2019-01-01' and ps.SITE_ID='AF' group by it.WAREHOUSE_ID, it.PART_ID) as io on ii.PART_ID = io.PART_ID and ii.WAREHOUSE_ID = io.WAREHOUSE_ID
where (ii.total_in - io.total_out) > 0
order by ii.WAREHOUSE_ID, ii.PART_ID

Any ideas?

Aug
27
1 month ago
Activity icon

Replied to Conditional Where Clauses Using Query Builder

Thanks for your input. I had my variables in an Eloquent collection already. After tinkering with the code, I think I found the solution:

$variableRevision = DB::connection('engineering')
                ->table('VariableValue as vv')
                ->join('Documents as d', 'd.DocumentID', '=', 'vv.DocumentID')
                ->select('VariableID', DB::raw('max(RevisionNo) as MaxRevisionNo'))
                ->where('d.Filename', '=', $this->partNumber . self::SOLIDWORKS_PART_FILE_EXTENSION)
                ->whereIn('vv.VariableID', self::PDM_VARIABLES)
                ->groupBy('vv.VariableID')
                ->get();

            $variableValues = DB::connection('engineering')
                ->table('VariableValue as vv')
                ->join('Variable as v', 'v.VariableID', '=', 'vv.VariableID')
                ->join('Documents as d', 'd.DocumentID', '=', 'vv.DocumentID')
                ->select('v.VariableName', 'vv.ValueText')
                ->where('d.Filename', '=', $this->partNumber . self::SOLIDWORKS_PART_FILE_EXTENSION);

            if($variableRevision->count() > 0)
            {
                $variableValues->where(function($query) use ($variableRevision, $variableValues){
                    $variableRevision->each(function($item, $key) use ($query, $variableValues){
                        $query->orWhere(function($q) use($item){
                           $q->where('vv.VariableID', '=', $item->VariableID)
                               ->where('vv.RevisionNo', '=', $item->MaxRevisionNo);
                        });
                    });
                });
            }
            $values = $variableValues->get();
Aug
26
1 month ago
Activity icon

Started a new Conversation Conditional Where Clauses Using Query Builder

I have one query that is dependent on the results of another. First, I run the following query against a SQL Server DB table:

$variableRevision = DB::connection('engineering')
                ->table('VariableValue as vv')
                ->join('Documents as d', 'd.DocumentID', '=', 'vv.DocumentID')
                ->select('VariableID', 'max(RevisionNo) as MaxRevisionNo')
                ->where('d.Filename', '=', $this->partNumber . self::SOLIDWORKS_PART_FILE_EXTENSION)
                ->whereIn('vv.VariableID', self::PDM_VARIABLES)
                ->get();

This query may return as many as 3 results. I would like to use the results of this query to generate the where clause of the following query:

SELECT v.VariableName, vv.ValueText
  FROM VariableValue as vv
  join Variable as v on v.VariableID = vv.VariableID
  join Documents as d on vv.DocumentID = d.DocumentID
  where d.Filename='151208.SLDPRT' and ((vv.VariableID=61 and vv.RevisionNo=3) or (vv.VariableID=62 and vv.RevisionNo=12) or (vv.VariableID=69 and vv.RevisionNo=12))
  order by vv.VariableID asc

How can I use the VariableIDs and MaxRevisionNos from the first query in the second query?

Aug
06
1 month ago
Activity icon

Replied to Forms, Query Strings, And Controller Parameters

I reviewed the Routing and Form Handling sections, but I didn't find what I was looking for. What did I miss?

Activity icon

Started a new Conversation Forms, Query Strings, And Controller Parameters

I have an HTML form that submits a GET request. Below is the Blade template for it:

@extends('base')

@section('content')
    @error('serial')
    <div class="alert alert-danger">{{ $message }}</div>
    @enderror
    <div class="row">
        <p>Type a part number into the box and press "Generate Report" (Example:
            <a href="{{ route('weldtub.show', ['serial' => '90114-624']) }}"> 90114-624</a>).</p>
        <p>Printing is optimized for the Chrome browser.
            <a href="javascript:window.print()"><em class="fi-print"></em> Click here to print.</a></p>
        <p>To print select tubs type desired page numbers under print preview (Example: 1-3 or 1,2,3)</p>
    </div>
    <div class="row">
        <form action="{{ route('weldtub.show', ['serial'])  }}" method="get">
            <label for="serial">Serial Number:</label>
            <input type="text" name="serial" value="{{ old('serial') or '' }}">
            <input type="submit" value="Generate" class="button postfix">
            @csrf
        </form>
    </div>
@endsection

The route definition is as follows:

Route::get('/fabrication/weldtub/{serial}', '[email protected]')->name('weldtub.show');

When the form submits, I would like it to use this route instead of appending a query string the the URL. How can I do that? If this isn't the right way to make this work, please point me in the right direction.

May
14
4 months ago
Activity icon

Started a new Conversation Relationships In Eloquent Collection

How can I retrieve the names of the relationships for a given Eloquent collection? Here is a sample model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Discount extends Model
{
    const MODIFIED_AT = 'DATE_MODIFIED';
    protected $connection = 'keystone';
    protected $table = 'DISCOUNTS';
    protected $primaryKey = 'DISCOUNT_ID';

    public function discountType()
    {
        return $this->hasOne('App\DiscountType', 'TYPE_ID', 'DISCOUNT_TYPE_ID');
    }

    public function getTable()
    {
        return $this->table;
    }

    public function getPrimaryKey()
    {
        return $this->primaryKey;
    }
}

How would I dynamically find the name of the discountType relationship without knowing it ahead of time?

Apr
23
5 months ago
Activity icon

Replied to Undefined Variable

Here's an interesting observation that I just made. If I set the variable in the controller, the value from the families Blade template will work. Why would I need to instantiate the variable in the controller?

public function showFamilies(){
        $families = $this->retrieveFamilyNames();
        return view('pricebook.families', [
            'title' => 'Price Book - Product Families',
            'tableID' => 'Random Value',
            'widgets' => [
                [
                    'id' => 'families',
                    'elements' => [
                        ['type' => 'table', 'formScript' => '/sales/pricebook/families/modify', 'tableID' => 'product-families', 'items' => $families->all(), 'index' => 'FAMILY_ID', 'hideAttr' => ['FAMILY_ID']]
                    ]
                ]
            ]
        ]);
    }
Activity icon

Replied to Undefined Variable

Here is the error:

Facade\Ignition\Exceptions\ViewException
Undefined variable: tableID (View: /mnt/c/Users/eric.drake/Documents/Sites/dev.keystone.local/resources/views/components/titlebar.blade.php) 

That file is the only one I have with "titlebar" in the name. I can't think of another that it would be trying to reference.

Activity icon

Replied to Undefined Variable

It returns the following:

array:9 [▼
  "__env" => Illuminate\View\Factory {#289 ▶}
  "app" => Illuminate\Foundation\Application {#2 ▶}
  "errors" => Illuminate\Support\ViewErrorBag {#288 ▶}
  "obLevel" => 1
  "title" => "product families"
  "widgets" => array:1 [▼
    0 => array:2 [▶]
  ]
  "tableID" => "product-families"
  "action" => "add"
  "buttonLabel" => "add families"
]
Activity icon

Started a new Conversation Undefined Variable

I'm new to Laravel and Blade templates. Here is my base template:

(base)

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>{{ $title }}</title>
    <link rel="stylesheet" href="{{ asset('css/common.css') }}" type="text/css"/>
</head>
<body>
@include('menu')
<div class="container">
    @yield('titlebar')
    @yield('content')
</div>
<div class="overlay">
    @section('overlay')
    @show
</div>
<script type="text/javascript" src="{{ asset('js/jquery-3.4.1.min.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/common.js') }}"></script>
</body>
</html>

Here is an extension of that template for a section of my site:

(pricebook.base)

@extends('base', ['title' => $title])

@section('titlebar')
@endsection

@section('content')
    @for($i = 0; $i < count($widgets); $i++)
        @include('components.widget', ['id' => $widgets[$i]['id'], 'elements' => $widgets[$i]['elements']])
    @endfor
@endsection

@section('overlay')
    @parent
@endsection

Finally, here is the template for the page I'm trying to generate:

(pricebook.families)

@extends('pricebook.base')

@section('titlebar')
    @parent
    @include('components.titlebar', [
        'tableID' => 'product-families',
        'title' => 'product families',
        'action' => 'add',
        'buttonLabel' => 'add families'
    ])
@endsection

@section('content')
    @parent
@endsection

@section('overlay')
    @parent
    @include('components.modal', [
        'modalTitle' => 'new family',
        'titleAction' => 'close',
        'titleButtonLabel' => 'close',
        'modalAction' => 'add',
        'modalButtonLabel' => 'add family'
    ])
@endsection

The titlebar section throws the error that the tableID variable is undefined. Here is the template for the titlebar:

(components.titlebar)

<div id="title-bar">
    <h1 class="page-title">{{ $title }}</h1>
    <div class="btn title-btn" data-action="{{ $action }}" data-related-table="{{ $tableID }}">
        <div class="lg-icon light-bg-icon icon-{{ $action }}"></div>
        <div class="btn-label">{{ $buttonLabel }}</div>
    </div>
</div>

Why would that variable be the only one of the array that is flagged as "undefined" by Laravel? I've tried moving that variable around within the array, so I know that's not happening just because I currently have it listed first. Any other thoughts?

Apr
02
5 months ago
Activity icon

Started a new Conversation Missing Episode

In the Object-Oriented Programming track, Episode 9 on Exceptions doesn't include a video to watch.

Upon further testing, I found that none of the videos on any of the tracks that I attempted to access are showing. I tried in three different web browsers.