eternalchaos520

eternalchaos520

Member Since 2 Years Ago

Experience Points
9,950
Total
Experience

50 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
96
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 2
9,950 XP
May
22
4 months ago
Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

To fulfill edit and store method

_method is important for perform update action.

edit.blade.php

<input name="_method" type="hidden" value="PATCH">
                                            @foreach($sc['sc_cp'] as $key => $value_one)
                                                <tr>
                                                    <td>
                                                        <input type="text" name="sc_cp[]" value="{{ $sc['sc_cp'][$key] }}" class="form-control" required="">
                                                    </td>
                                                    <td>
                                                        <input type="text" name="sc_material[]" value="{{ $sc['sc_material'][$key] }}" class="form-control" required="">
                                                    </td>
                                                    <td>
                                                        <input type="text" name="sc_grade[]" value="{{ $sc['sc_grade'][$key] }}" class="form-control" required="">
                                                    </td>
                                                    <td class="align-middle">
                                                        <a href="#" class="btn btn-danger removeRow">Remove</a>
                                                    </td>
                                                </tr>
                                            @endforeach

                                            <script type="text/javascript">
                                                $('.addRow').on('click', function(){
                                                    addRow();
                                                });
                                                function addRow() {
                                                    var tr = 
                                                    '<tr>' + 
                                                        '<td>' + 
                                                        '<input type="text" name="sc_cp[]" class="form-control"> required' +
                                                        '</td>' + 
                                                        '<td>' + 
                                                        '<input type="text" name="sc_material[]" class="form-control"> required' +
                                                        '</td>' +
                                                        '<td>' + 
                                                        '<input type="text" name="sc_grade[]" class="form-control"> required' +
                                                        '</td>' +
                                                        '<td>' + 
                                                        '<a href="#" class="btn btn-danger removeRow">Remove</a>'
                                                        '</td>' +
                                                    '</tr>';
                                                    $('tbody').append(tr);
                                                }
                                                $('tbody').on('click', '.removeRow', function(){
                                                    $(this).parent().parent().remove();
                                                });
                                            </script>

Controller

    public function update(Request $request, $id)
    {
        $sc = Sc::find($id);
        $sc->sc_cp = $request->get('sc_cp');
        $sc->sc_material = $request->get('sc_material');
        $sc->sc_grade = $request->get('sc_grade');

        $sc->save();

        return redirect('/sc')->with('success', 'Data updated successfully!');
    }

Hope it will help the community.

May
20
4 months ago
Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

@bobbybouwmann

Wow, it work like a charm, from beginning I was doing like this

                @foreach($sc['sc_cp'] as $key => $value_one)
                    <tr>
                        <td>{{ $value_one }}</td>
                        @foreach($sc['sc_material'] as $key => $value_two)
                            <td colspan="2">{{ $value_two }}</td>
                        @endforeach
                        @foreach($sc['sc_grade'] as $key => $value_three)   
                            <td>{{ $value_three }}</td>
                        @endforeach 
                    </tr>
                @endforeach
Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

@kundefine hmm, it is working, I thought it required to use for loop to get the result.

is that possible to print index[1] as second tr?

Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

@bobbybouwmann dd result is returning the all the attribute

dd result

  #fillable: array:12 [▼ ▼
    0 => "sc_customer"
    1 => "sc_model"
    2 => "sc_no"
    3 => "quantity"
    4 => "sc_name"
    5 => "refer_sc_no"
    6 => "mo_no"
    7 => "sc_cp"
    8 => "sc_material"
    9 => "sc_grade"
  ]
  #casts: array:3 [▶ ▼
    "sc_cp" => "array"
    "sc_material" => "array"
    "sc_grade" => "array"
  ]
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:15 [▶ ▼
    "id" => 2
    "sc_customer" => "qwer"
    "sc_model" => "qwer"
    "sc_no" => "qwer"
    "quantity" => "qwer"
    "sc_name" => "qwer"
    "refer_sc_no" => "qwer"
    "mo_no" => "qwer"
    "sc_cp" => "["qwer","qwer"]"
    "sc_material" => "["qwer","qwer"]"
    "sc_grade" => "["qwer","qwer"]"
    "created_at" => "2019-05-20 08:30:51"
    "updated_at" => "2019-05-20 08:30:51"
  ]
  #original: array:15 [▶ ▼
    "id" => 2
    "sc_customer" => "qwer"
    "sc_model" => "qwer"
    "sc_no" => "qwer"
    "quantity" => "qwer"
    "sc_name" => "qwer"
    "refer_sc_no" => "qwer"
    "mo_no" => "qwer"
    "sc_cp" => "["qwer","qwer"]"
    "sc_material" => "["qwer","qwer"]"
    "sc_grade" => "["qwer","qwer"]"
    "created_at" => "2019-05-20 08:30:51"
    "updated_at" => "2019-05-20 08:30:51"

The question is how to passing array to view.

Activity icon

Replied to Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

@bobbybouwmann I search around internet, as I reviewed some of code is using @foreach to get the result. Could you advice some solution or tutorial for me?

May
19
4 months ago
Activity icon

Started a new conversation Htmlspecialchars() Expects Parameter 1 To Be String, Array Given

Hi Community,

when I tried to cast sc_cp, sc_material, sc_grade to array in model.

Store method is work perfectly by storing the data into database and the field does store as array, however when I tried to passing to view in show method, it returns the error as below.

htmlspecialchars() expects parameter 1 to be string, array given.

Another question is that how do I get the old value in edit method and update accordingly in the dynamic input box.

Please note that there is only 1 model involved.

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Sc extends Model
{
    protected $fillable = [
        'sc_customer',
        'sc_model',
        'sc_no',
        'quantity',
        'sc_name',
        'refer_sc_no',
        'mo_no',
        'sc_cp',
        'sc_material',
        'sc_grade',
    ];

    protected $casts = [
        'sc_cp' => 'array',
        'sc_material' => 'array',
        'sc_grade' => 'array',
    ];
}

Controller

<?php

namespace App\Http\Controllers;

use App\Sc;
use Illuminate\Http\Request;

class ScController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $scs = Sc::all()->toArray();

        return view('sc.index', compact('scs'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('sc.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = array

        $sc = new Sc([
            'sc_customer' => $request->get('sc_customer'),
            'sc_model' => $request->get('sc_model'),
            'sc_no' => $request->get('sc_no'),            
            'quantity' => $request->get('quantity'),
            'sc_name' => $request->get('sc_name'),
            'refer_sc_no' => $request->get('refer_sc_no'),
            'mo_no' => $request->get('mo_no'),
            'sc_cp' => $request->get('sc_p'),
            'sc_material' => $request->get('sc_material'),
            'sc_grade' => $request->get('sc_grade'),
        ]);

        $sc->save();

        return redirect('sc');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $sc = sc::find($id);

        return view('sc.show', compact('sc', 'id'));
    }

}

create.blade.php

@extends('layouts.app')

@section('styles')
    <style>
        #print-btn {
            display: none;
        }
    </style>
@endsection

@section('content')
    <div class="container py-5">
        <div class="row">
            <div class="col-md-12">
                <div class="row">
                    <div class="col-md-10 offset-md-1">
                        <span class="anchor" id="formUserEdit"></span>
                        <!-- MyTech Part Description Form -->
                        <div class="card card-outline-secondary">
                            <div class="card-body">
                                <form class="form" role="form" autocomplete="off" method="post" action="{{ url('sc') }}">
                                    {{ csrf_field() }}
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="sc_customer_label">Customer:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="sc_customer_input" type="text" name="sc_customer" value="" required>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="sc_model_label">Model:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="sc_model_input" type="text" name="sc_model" value="" required>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="sc_no_label">Part No:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="sc_no_input" type="text" name="sc_no" value="" required>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="quantity_label">Quantity:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="quantity_input" type="text" name="quantity" value="" required>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="sc_name_label">Part Name:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="sc_name_input" type="text" name="sc_name" value="" required>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="refer_sc_no_label">Refer. No:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="refer_sc_no_input" type="text" name="refer_sc_no" value="" required>
                                        </div>
                                    </div>                                    
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label" id="mo_no_label">Manufacturing No:</label>
                                        <div class="col-lg-9">
                                            <input class="form-control" id="mo_no_input" type="text" name="mo_no" value="" required>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <table class="table table-bordered">
                                            <thead>
                                                <tr>
                                                    <td class="align-middle">CP:</td>
                                                    <td class="align-middle">Material:</td>
                                                    <td class="align-middle">Grade:</td>
                                                    <td class="align-middle">
                                                        <a href="#" class="btn btn-primary addRow">Add</a>
                                                    </td>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <td>
                                                    <input type="text" name="sc_cp[]" class="form-control">
                                                </td>
                                                <td>
                                                    <input type="text" name="sc_material[]" class="form-control">               
                                                </td>
                                                <td>
                                                    <input type="text" name="sc_grade[]" class="form-control">
                                                </td>
                                                <td class="align-middle">
                                                    <a href="#" class="btn btn-danger removeRow">Remove</a>
                                                </td>                                 
                                            </tbody>
                                        </table>
                                    </div>                                
                                    <div class="form-group row">
                                        <label class="col-lg-3 col-form-label form-control-label"></label>
                                        <div class="col-lg-9">
                                            <input type="reset" class="btn btn-danger" value="Reset">
                                            <input type="submit" class="btn btn-info" value="Save Changes">
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                <br><br><br><br>
            </div>
        </div>
        <hr>
    </div>
    <!--/container-->
@endsection

@section('scripts')
    <script>
        $('.addRow').on('click', function(){
            addRow();
        });
        function addRow() {
            var tr = 
            '<tr>' + 
                '<td>' + 
                '<input type="text" name="sc_cp[]" class="form-control">' +
                '</td>' + 
                '<td>' + 
                '<input type="text" name="sc_material[]" class="form-control">' +
                '</td>' +
                '<td>' + 
                '<input type="text" name="sc_grade[]" class="form-control">' +
                '</td>' +
                '<td>' + 
                '<a href="#" class="btn btn-danger removeRow">Remove</a>'
                '</td>' +
            '</tr>';
            $('tbody').append(tr);
        }
        $('tbody').on('click', '.removeRow', function(){
            $(this).parent().parent().remove();
        });        
    </script>
@endsection

show.blade.php

<div class="container">
    <div class="row">
        <div class="col-sm">
            <table>
                <tr>
                    <td>CHILD PART</td>
                    <td colspan="2">MATERIAL</td>
                    <td>GRADE</td>                    
                </tr>
                <tr>
                    <td>{{$sc['sc_cp']}}</td>
                    <td colspan="2">{{$sc['sc_material']}}</td>
                    <td>{{$sc['sc_grade']}}</td>                    
                </tr>
            </table>
        </div>
    </div>
</div>

Jan
30
8 months ago
Activity icon

Replied to Multiple Database On Same Server Join Query

in the end I used sql view to join the query first then using query builder to get the data.

Jan
23
8 months ago
Activity icon

Replied to Multiple Database On Same Server Join Query

@VILFAGO - I had tried to code it my own but failed, that's why I open a thread here. As I tested so far, the default db can be connected without using DB:connection, however the second db is required to use DB:connection in order to connect it.

Is there anyway to connect second database with left join at the same time?

                   DB::Connection('sqlsrv')
                    ->table('CHECKINOUT')
                    ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
                    ->leftjoin(DB::Connection('sqlsrv2'))                       
                        ->table('EMPLOYEE', 'USERINFO.CardNo', '=', 'EMPLOYEE.CardID')
                    ->get();

If there is the solution can resolve connection part then I think my problem can be solved.

Activity icon

Replied to Multiple Database On Same Server Join Query

@VILFAGO - Erm, I am not intend to create the model to manipulate the data, I just want to extract data from database only.

Activity icon

Started a new conversation Multiple Database On Same Server Join Query

Hi, I had been searching for the solution in the internet for a long time but still I couldn't find the solution, most of the search results is joining on different tables in single database.

I need the solution for different DB::Connection left join and get the query results.

Please noted that I only want to view the results only, no any CRUD required.

Moreover, all databases are within the same server, if using single connection like DB::connection('sqlsrv') or ('sqlsrv2') can get the result easily only when join is having issues.

Below are my codes so far.

<?php

namespace App\Http\Controllers;

use App\UserInfo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class UserInfoController extends Controller
{
    public function index() 
    {       
        // $UserInfos = DB::connection('sqlsrv2')->select('select * from TMS_CLOCKING');                            
        // $userinfos = DB::connection('sqlsrv')->select('select * from userinfo');

        // $userinfos = DB::table('USERINFO')->where('USERID', '=', '252')->get();      
        // $userinfos = DB::table('CHECKINOUT')
        //          ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
        //          ->where('USERINFO.CardNo', '=', '1411078')
        //          ->get();


        // $db = DB::connection('sqlsrv2');

        $employee_profile = 
                    DB::connection('sqlsrv2')
                    ->table('EMPLOYEE')
                    ->where('ISACTIVE', '=', 'Y')
                    ->where('CARDID', '!=', '')
                    ->where('DEPARTMENT', '!=', '')
                    ->get();

        // $employee_attendance =
        //          DB::table('CHECKINOUT')
        //          ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
        //          ->leftJoin('TMS_EMPLOYEE', 'USERINFO.CardNo', '=', 'TMS_EMPLOYEE.CardID')
        //          ->get();

        // $db = DB::Connection('sqlsrv2')->('EMPLOYEE');
        // $employee_attendance =
        //          DB::table('CHECKINOUT')
        //          ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
        //          ->leftjoin($db, 'USERINFO.CardNo', '=', 'EMPLOYEE.CARDID')
        //          ->get();

        $employee_attendance =
                    DB::Connection('sqlsrv')
                    ->table('CHECKINOUT')
                    ->leftJoin('USERINFO', 'CHECKINOUT.USERID', '=', 'USERINFO.USERID')
                    ->leftjoin(DB::Connection('sqlsrv2'))                       
                        ->table('EMPLOYEE', 'USERINFO.CardNo', '=', 'EMPLOYEE.CardID')
                    ->get();

        $employee_attendance = 
                    DB::table(DB::raw('EMPLOYEE'))

        // $userinfos = $employee_profile;
        $userinfos = $employee_attendance;

        return view('userinfo.index', ['userinfos' => $userinfos]);     
    }
}

Nov
27
10 months ago
Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

Wow, it is working, I don't even know that uppercase affect that much. It does work on mssql as well.

Thanks for your support.

Thumbsup~

Nov
26
10 months ago
Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

@D9705996

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Clocking extends Model
{
    protected $table = 'checkinout';

    protected $primaryKey = 'USERID';

    protected $fillable = [
        'USERID',
        'CHECKTIME',
        'CHECKTYPE',
        'VERIFYCODE',
        'SENSORID',
        'LOGID',
        'MachineId',
        'UserExtFmt',
        'WorkCode',
        'MemoInfo',
        'sn'
    ];
}

Controller

<?php

namespace App\Http\Controllers;

use App\Clocking;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Carbon\Carbon;

class ClockingController extends Controller
{
    public function index() 
    {       
        $clockings = DB::table('checkinout')
                    ->orderby('checktime', 'DESC')
                    ->whereDate('checktime', Carbon::today())
                    ->get();

        // $clockings = Clocking::findOrFail(1);            

        // $result = json_decode($clockings, true);             
        // return $result;

        return view('clocking.index', ['clockings' => $clockings]);
        // dd($clockings);
        // var_dump($clockings);

    }
}

View

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Clocking</title>
</head>
<body>
 
<table border="1">
    <thead>
        <tr>
            <th>UserId</th>
            <th>Checktime</th>
        </tr>
    </thead>
    <tbody>

        <td>{{ dd($clockings) }}<td>
    </tbody>
</table>
 
</body>
</html>
Output for the view


UserId  Checktime
Collection {#2107 ▼
  #items: array:1702 [▼
    0 => {#404 ▼
      +"USERID": "2851"
      +"CHECKTIME": "2018-11-27 10:26:13.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "43582091"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OMY7050067052700007"
    }
    1 => {#405 ▶}
    2 => {#406 ▶}
Nov
05
11 months ago
Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

@D9705996

Other property also having empty results but dd and var dump do return the values.

Please note that I am using ?? null else it will return non-object errors {{ $clocking->USERID ?? null }}

Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

@D9705996 Hmm, it is uppercase in the database, as I follow the code you given, still remain the same issues, return empty results in view.

Nov
04
11 months ago
Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Clocking extends Model
{
    protected $table = 'checkinout';

    protected $primaryKey = 'USERID';

    protected $fillable = [
        'USERID',
        'CHECKTIME',
        'CHECKTYPE',
        'VERIFYCODE',
        'SENSORID',
        'LOGID',
        'MachineId',
        'UserExtFmt',
        'WorkCode',
        'MemoInfo',
        'sn'
    ];
}

Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

@bluemagenta

As I tried the solution, I am using php 7, at least it does not have any errors now.

however there's no output within the td tag

Below is the dd output, it seems like it could get the data from the database but still could not output on the view. The code is remained the same just changed to this only

{{ $clocking->checktime ?? null }}
dd output

Collection {#1756 ▼
  #items: array:1347 [▼
    0 => {#408 ▼
      +"USERID": "13"
      +"CHECKTIME": "2018-11-05 10:04:14.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "41570469"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OTH7050067042900001"
    }
    1 => {#409 ▼
      +"USERID": "3056"
      +"CHECKTIME": "2018-11-05 09:02:34.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "41423870"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OMY7050067052700007"
    }
    2 => {#410 ▼
      +"USERID": "85"
      +"CHECKTIME": "2018-11-05 09:02:21.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "41423869"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OTH7050067042900001"
    }
    3 => {#411 ▼
      +"USERID": "2785"
      +"CHECKTIME": "2018-11-05 08:52:09.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "41423868"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OMY7050067052700007"
    }
    4 => {#412 ▼
      +"USERID": "1036"
      +"CHECKTIME": "2018-11-05 08:51:17.000"
      +"CHECKTYPE": "I"
      +"VERIFYCODE": "15"
      +"SENSORID": "1"
      +"LOGID": "41423867"
      +"MachineId": null
      +"UserExtFmt": "0"
      +"WorkCode": "0"
      +"Memoinfo": null
      +"sn": "OTH7050067042900001"
    }

Oct
08
1 year ago
Activity icon

Replied to Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

@D9705996 Since dd, dump and var_dump can get the data so I don't think the connection DB is having any issues. However I already changed to what you mentioned in comment 1, for the comment 2, I am using the same env as you mentioned.

@RamjithAp I already added the if condition in views portion but still having the same error either using count() > 0 or count(). Undefined property: stdClass::$checktime

Activity icon

Started a new conversation Unable To Populate Data Laravel 5.4 Query Builder Display Query Data In Views

Hi, I had been struggling for the issues for a day, I been looking on stackoverflow and related solution but seems like it works well with particular case.

My case is a little bit different, I am using sqlsrv as my database engine, I just wanted to for loop the rows from my database to my web application with some styling.

Please note that using dd or dump or var_dump can view the data but I prefer cleaner way to display in view.

It returns Undefined property: stdClass::$checktime error when I try to display in views.

Since I just wanted to view the data so I don't think I need to create the model(correct me if I am wrong).

Any help will be appreciated.

Controller Part
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Carbon\Carbon;
use DB;

class ClockingController extends Controller
{
    public function index() 
    {       
        $clockings = DB::table('checkinout')
                    ->orderby('checktime', 'DESC')
                    ->whereDate('checktime', Carbon::today())
                    ->get();

        return view('clocking.index', ['clockings' => $clockings]);
    }
}
Views Part
<table border="1">
    <tr>
        <th>UserId</th>
        <th>Checktime</th>
    </tr>
    @foreach($clockings as $clocking)
        <tr>
            <td>{{ $clocking->checktime }}</td>            
        </tr>
    @endforeach
</table>