Ain

Ain

Member Since 8 Months Ago

Experience Points
4,430
Total
Experience

570 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
0
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
4,430 XP
Nov
15
4 days ago
Activity icon

Started a new Conversation Too Few Arguments To Function

Im getting this error, anybody know how to solve it?

https://imgur.com/a/RQiXQ5R

image.blade.php

{!! Form::open(['method'=>'POST', 'action'=>'[email protected]', 'files'=>true]) !!}

<div class="form-group">
    <input type="hidden" name="id" id="id" value="{{$ms->id}}">
</div>

<div class="form-group">
    {!! Form::file('file',['class'=>'form-control col-sm-4']) !!}
</div>
<br>
<div class="form-group">
    {!! Form::submit('Upload ', ['class'=>'btn btn-primary btn-lg col-sm-4']) !!}
</div>

<button type="button" class="btn btn-lg col-sm-4"  onClick="javascript:history.go(-1)"> Back </button>
<br/>

{{csrf_field()}}
{!! Form::close() !!}

web.php

Route::post('/masterStockist/image', '[email protected]');

Route::get('/masterStockist/image/{id}', '[email protected]')->name('masterStockist.image');

ImageController.php

    public function store(Request $request, $id)
    {
        $input = $request->all();

        if($file = $request->file('file')){

            $name = $file->getClientOriginalName();

            $file->move('images', $name);

            $input ['image'] = $name;
        }
        $upload_to_restock = Restock::findOrFail($id);
        $upload_to_restock->image()->create(['file'=>$name]);
    }
Nov
14
5 days ago
Activity icon

Started a new Conversation Storing Foreign Key

If I have an entity relationship diagram (ERD) looks like this https://imgur.com/a/tiriw7H , how do I store the "image_restock_id" in the image table into the database?

ImageController.php

    public function store(Request $request)
    {
        $input = $request->all();

        if($file = $request->file('file')){

            $name = $file->getClientOriginalName();

            $file->move('images', $name);

            $input ['image'] = $name;

        }
        Image::create($input);
    }
Activity icon

Replied to Upload Image

@sinnbeck @tangente , sorry i uploaded the wrong image. already edited it.

Activity icon

Replied to Upload Image

@tangente im getting this error, do you perhaps know why and how to solve it?

Error https://imgur.com/a/3jmnQQg

When I do the dd($request) https://imgur.com/a/BY1IRPJ

UploadPictureController.php

    public function store(Request $request)
    {
        $input = $request->all();

        if($file = $request->file('file')){

            $name = $file->getClientOriginalName();

            $file->move('images', $name);

            $input ['image'] = $name;

        }
        Restock::create($input);
        
    }
Nov
13
6 days ago
Activity icon

Replied to Upload Image

hi @tangente ,

the relationship is one-to-many https://imgur.com/a/51JGZGS. Do i have to do the 'create' like many-to-many relationship?

If yes, would you mind to explain how do i associate the record id to each upload entry?

Activity icon

Started a new Conversation Upload Image

I want user to upload image only after they submit the other details. Because after they submit, only then the total will be calculated.

below is the sequences :

  1. https://imgur.com/a/0XWIJHG

  2. https://imgur.com/a/rmt2jzr

  3. (after user click "Click here") https://imgur.com/a/a4y4KFX

The question is, during uploading the image, does it considered as create or edit?

Nov
11
1 week ago
Activity icon

Replied to Store Image

thankyou @mware . I have another question. Do you know how to save the image field only? Because it been asking for all the data for each column down below.

    protected $fillable = [
    'restock_user_id',
    'address',
    'phone_no',
    'date',
    'total',
    'status_id',
    'tracking_no',
    'image'

The error https://imgur.com/a/7KIskE2

Activity icon

Replied to Store Image

@jlrdw

I need to store the image to a specific user, by using "restock_user_id". Do you perhaps know how to do it?

$this->validate($request, [
'select_file'  => 'image|max:2048'
]);

$image = $request->file('select_file');

$new_name = rand() . '.' . $image->getClientOriginalExtension();

$image->move(public_path('images'), $new_name);

Restock::create([
'image'=>$new_name,
]);

return redirect()->back()->with('success', 'Image Uploaded Successfully')->with('path', $new_name);

Because after the user fill in others detail -> submit ->index : only then the upload image button appears. Because the total only appear once the user click submit.

Receipt: user need to transfer the money after know the total

Activity icon

Replied to Store Image

Hi @jlrdw , im not quite understand. Do I have to make a new folder name "images" under the public folder?

Update: It actually there https://imgur.com/a/8g9TZOf but it does not store into the database https://imgur.com/a/zJRSdIQ

Or does it actually store there instead of the database?

Activity icon

Started a new Conversation Store Image

How do we store an image into the database? Because in the tutorial I follow, it only upload it

https://www.webslesson.info/2018/02/image-file-upload-in-laravel-with-validation.html

index.blade.php

<td>
    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
    </head>
    <body>
    <br />
    @if (count($errors) > 0)
        <div class="alert alert-danger">
            Upload Validation Error<br><br>
            <ul>
                @foreach ($errors->all() as $error)
                    <li>{{ $error }}</li>
                @endforeach
            </ul>
        </div>
    @endif
    @if ($message = Session::get('success'))
        <div class="alert alert-success alert-block">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>{{ $message }}</strong>
        </div>
        <img src="/images/{{ Session::get('path') }}" width="300" />
    @endif
    <form method="post" action="{{url('/masterStockist')}}" enctype="multipart/form-data">
        {{ csrf_field() }}
        <table class="table">
            <p width="30"><input type="file" name="select_file" /></p>
            <p width="30%" align="left"><input type="submit" name="upload" class="btn btn-primary" value="Upload"><span class="text-muted col-md-2">jpg, png, jpeg</span></p>
        </table>
    </form>
    </body>
    </html>
</td>

UploadPictureController.php

function upload(Request $request)
    {
        $this->validate($request, [
            'select_file'  => 'image|max:2048'
        ]);

        $image = $request->file('select_file');

        $new_name = rand() . '.' . $image->getClientOriginalExtension();

        $image->move(public_path('images'), $new_name);
        return redirect()->back()->with('success', 'Image Uploaded Successfully')->with('path', $new_name);
    }

web.php

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

Migration

$table->string('image')->nullable();
Activity icon

Replied to Imgur.com

alright @bobbybouwmann , thank youuu :)

Activity icon

Started a new Conversation Imgur.com

How long does imgur.com store the picture we paste there?

Nov
07
1 week ago
Activity icon

Replied to "Forgot Your Password?" - Login

In this video, it shows this at the end of it https://imgur.com/a/lv3aLTR

https://www.youtube.com/watch?v=jNdVW8lsFOo

Can someone explain to me why does it log out as user and log in back as admin? Does it convert its role from normal user to admin?

Activity icon

Started a new Conversation "Forgot Your Password?" - Login

In order yo use the "Forgot Your Password" function, does we have to do any configuration for it? If yes, how to do it? Where to start?

Because im getting this error after clicking on "Send password reset link" button.

https://imgur.com/a/C4aRp5I

Nov
06
1 week ago
Activity icon

Awarded Best Reply on Delete Button Not Functioning

Already found the answer. The coding below

{!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}

Should be like this

{!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $ms->id]]) !!}
Activity icon

Replied to Delete Button Not Functioning

Already found the answer. The coding below

{!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}

Should be like this

{!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $ms->id]]) !!}
Activity icon

Replied to Delete Button Not Functioning

Im so sorry @snapey , im not sure therefore i provide all the related coding in this reply. And I seriously have o idea on how to fix this.

Unit.php (model)

class Unit extends Model
{
    protected $fillable = [

        'restock_id',
        'desc_shampoo',
        'desc_balm',
        'qty_shampoo',
        'qty_balm'
    ];

    public function restock()
    {
        return $this->belongsTo('App\Restock');
    }
}

Restock.php

class Restock extends Model
{
    protected $fillable = [
    'restock_user_id',
    'address',
    'phone_no',
    'date',
    'total',
    'status',
    'tracking_no'
];

    public function unit()
    {
        return $this->hasOne('App\Unit');
    }
}

MasterStockistController.php

class MasterStockistController extends Controller
{
    public function index()
    {
        $userId = Auth::user()->id;

        $restock = Restock::all();

        $mstrStockist = Restock::where('restock_user_id',$userId)->get();

        return view('masterStockist.index',compact('mstrStockist', 'userId', 'restock'));
    }

    public function destroy(Restock $restock)
    {
        $restock->delete();
        Unit::where('restock_id',$restock->id)->delete();

        //Create session to display Flash message
        Session::flash('delete_restock_success', 'Successful deleted restock record!');

        return redirect()->back();
    }
}

web.php

Route::delete('/masterStockist/{restock}', '[email protected]');

index.php

<tbody>
@if($mstrStockist)
    @foreach($mstrStockist as $ms)
        <tr>
            {{--Display no--}}
            <td>{{ $loop->iteration }}</td>

            {{--Display name--}}
            @if($ms->user)
                <td>{{$ms->user->name}}</td>
            @endif

            {{--Display ID--}}
            @if($ms->user)
                <td>{{$ms->user->user_id}}</td>
            @endif

            {{--Display address--}}
            <td>{{$ms->address}}</td>

            {{--Display phone no--}}
            <td>{{$ms->phone_no}}</td>

            {{--Display date--}}
            <td>{{$ms->date}}

            @if($ms->unit)
                <td><p style="background-color:hsl(210, 100%, 80%);">{{ $ms->unit->desc_shampoo }}</p><hr>

                    <p style="background-color:hsl(80, 100%, 70%);">{{ $ms->unit->desc_balm }}</p></td>

                <td><p style="background-color:hsl(210, 100%, 80%);">{{ $ms->unit->qty_shampoo }}</p><hr>

                    <p style="background-color:hsl(80, 100%, 70%);">{{ $ms->unit->qty_balm }}</p></td>
            @endif

            {{--Display total--}}
            <td>{{$ms->total}}</td>

            {{--Display status--}}
            <td>
                <em>{{$ms->status}}</em>
                <hr>
                {{$ms->tracking_no}}
            </td>

            {{--Display delete button--}}
            {!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}
            <td>
                <button type="submit" class="btn btn-danger" onclick="return confirm('Are you sure want to delete?')">Delete</button>
            </td>
            {!! Form::close() !!}

        </tr>
    @endforeach
@endif
</tbody>
Activity icon

Replied to Delete Button Not Functioning

@snapey already added the coding and it says

Property [id] does not exist on this collection instance.

Activity icon

Replied to Delete Button Not Functioning

I already try @armani and @siangboon suggestion, but both, when i clicked the delete button, nothing happen. I dont know, what should i do :(

Activity icon

Replied to Delete Button Not Functioning

@sergiu17 it shows

Property [id] does not exist on this collection instance. (View: C:\xampp\htdocs\lespettua\resources\views\masterStockist\index.blade.php)

Activity icon

Started a new Conversation Delete Button Not Functioning

I put the delete button in index, but its not working.

index.blade.php

{{--Display delete button--}}
    {!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}
    <button type="submit" class="btn btn-danger btn-lg col-sm-12" onclick="return confirm('Are you sure want to delete?')">Delete</button>
    {!! Form::close() !!}

MasterStockistController.php

    public function destroy(Restock $restock)
    {
        $id = $restock->id;

        Restock::findOrFail($id)->delete();

        Unit::where('restock_id',$id)->delete();

        //Create session to display Flash message
        Session::flash('delete_restock_success', 'Successful deleted restock record!');

        return redirect('/masterStockist');
    }
Nov
05
2 weeks ago
Activity icon

Replied to Disable Link

@jaytee

I already edit the above question, sorry to confuse you, its actually 'Pending' and Submitted'.

if the status is not integer but string, do i have to adjust back all the coding for it to become integer?

Activity icon

Started a new Conversation Disable Link

I have 2 situation (status) , Pending and Submitted

what should i do if i want to disable the link or maybe popup something (saying that it cannot be edit) to the user if the status is already "Submitted"?

https://imgur.com/a/4fFkXOS

{{--Display name--}}
@if($ms->user)
    <td><a href="{{route('masterStockist.edit', $ms)}}">{{$ms->user->name}}</a></td>
@endif
Nov
04
2 weeks ago
Activity icon

Replied to GET Method Is Not Supported For This Route. Supported Methods: PUT.

@nakov

when i changed Route:put to Route:get , this error shows

https://imgur.com/a/L1ylXsZ

Activity icon

Replied to GET Method Is Not Supported For This Route. Supported Methods: PUT.

@nakov

index.blade.php

{{--Display name--}}
{{--Accessing the edit blade through this--}}
@if($ms->user)
    <td><a href="{{route('masterStockist.edit', $ms)}}">{{$ms->user->name}}</a></td>
@endif

edit.blade.php

<h1>Edit Restock Details</h1>

{!! Form::model($restock, ['method' => 'PATCH', 'action' => ['[email protected]', $restock->id]]) !!}

{!! Form::label('address', 'Address:') !!}
{!! Form::text('address', null, ['class' => 'form-control', 'placeholder' => 'Address', 'required' => 'required']) !!}

{!! Form::label('phone_no', 'Phone Number:') !!}
{!! Form::text('phone_no', null, ['class' => 'form-control', 'placeholder' => 'Eg. 019-4568765', 'required' => 'required']) !!}

{!! Form::label('date', 'Date:') !!}
{!! Form::date('date', null, ['class' => 'form-control', 'placeholder' => 'Date', 'required' => 'required']) !!}


<h3>Item:</h3>

<div class="form-group">
    <td>
        <form action="" method="POST">
            <div class="form-group" >
                <input type="hidden" name="desc_shampoo" id="desc_shampoo" value="Shampoo">
                <input type="text" name="desc_shampoo" value="Shampoo" id="desc_shampoo" disabled>
                <input type="number" name="qty_shampoo" placeholder="Quantity" value="{{ $restock->unit->qty_shampoo }}" id="qty_shampoo" min="400" max="5000" >
            </div>

            <div class="form-group">
                <input type="hidden" name="desc_balm" id="desc_balm" value="Balm">
                <input type="text" name="desc_balm" value="Balm" id="desc_balm" disabled>
                <input type="number" name="qty_balm" placeholder="Quantity" value="{{ $restock->unit->qty_balm }}" id="qty_balm" min="400" max="5000" >
            </div>

            <div class="form-group">
                <input type="hidden" name="status" id="status" value="Pending">
            </div>
        </form>

        <br/>
        {!! Form::submit('Edit', ['class'=>'btn btn-primary btn-lg col-sm-12']) !!}
        <hr>
        {!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}

        <button type="submit" class="btn btn-danger btn-lg col-sm-12" onclick="return confirm('Are you sure want to delete?')">Delete</button>
        {!! Form::close() !!}
    </td>
</div>
Activity icon

Started a new Conversation GET Method Is Not Supported For This Route. Supported Methods: PUT.

Im getting below error while trying to viewing edit.blade.php

The GET method is not supported for this route. Supported methods: PUT.

The thing is, i got 2 edit.blade.php, under different folder but directing to the same controller.

web.php

Route::resource('/restocks', 'RestockController');

Route::get('/masterStockist', '[email protected]')->name('masterStockist.index');

//error after adding this route
Route::put('/masterStockist/{id}/edit', '[email protected]')->name('masterStockist.edit');
Activity icon

Replied to Calculate Total & Store It

@bobbybouwmann I already try the one you suggested, and its working plus its quite simple and easy to understand :)

but i have some issue, the above coding is for store. And i dont know where to calculate in the update. Below is my update function in controller

    public function update(Request $request, $id)
    {
        $request->validate([
            'qty_shampoo' => 'numeric|min:400',
            'qty_balm' => 'numeric|min:400',
        ]);

        $restock = Restock::findOrFail($id);

        $restock->update($request->merge([
            'restock_user_id'=> Auth::id()
        ])->only(['address','phone_no','date','total','restock_user_id']));

        $restock->unit->update($request->merge([
            'restock_id'=>  $restock -> id
        ])->only(['desc_shampoo','desc_balm','qty_shampoo','qty_balm','restock_id']));

        //Create session to display Flash message
        Session::flash('edit_restock_success', 'Successful edited restock details!');

        return redirect()->back();
    }
Activity icon

Replied to Calculate Total & Store It

@sinnbeck yes, only 2 item and the price never change.

@bobbybouwmann this is how i store, below is the create.blade.php

<h1>Restock</h1>

{!! Form::open(['method' => 'POST', 'action' => ['[email protected]']]) !!}

{!! Form::label('address', 'Address:') !!}
{!! Form::text('address', null, ['class' => 'form-control', 'placeholder' => 'Address', 'required' => 'required']) !!}

{!! Form::label('phone_no', 'Phone Number:') !!}
{!! Form::text('phone_no', null, ['class' => 'form-control', 'placeholder' => 'Eg. 019-4568765', 'required' => 'required']) !!}

{!! Form::label('date', 'Date:') !!}
{!! Form::date('date', null, ['class' => 'form-control', 'placeholder' => 'Date', 'required' => 'required']) !!}

<h5>Item:</h5>

<div class="form-group">
    <td>

        <form action="" method="POST">
            <div class="form-group" >
                <input type="hidden" name="desc_shampoo" id="desc_shampoo" value="Shampoo">
                <input type="text" name="desc_shampoo" value="Shampoo" id="desc_shampoo" disabled>
                <input type="number" name="qty_shampoo" placeholder="Quantity" id="qty_shampoo" min="400" max="5000" >
            </div>

            <div class="form-group">
                <input type="hidden" name="desc_balm" id="desc_balm" value="Balm">
                <input type="text" name="desc_balm" value="Balm " id="desc_balm" disabled>
                <input type="number" name="qty_balm" placeholder="Quantity" id="qty_balm" min="400" max="5000" >
            </div>
        </form>

        {!! Form::label('total', 'Total (RM):') !!}
        {!! Form::text('total', null, ['class' => 'form-control', 'placeholder' => 'Total', 'required' => 'required']) !!}
        <br/>
        {!! Form::submit('Submit', ['class'=>'btn btn-primary btn-lg col-sm-12']) !!}
    </td>
</div>

{!! Form::close() !!}
Activity icon

Replied to Calculate Total & Store It

@bobbybouwmann

shampoo: $22/unit balm: $28/unit

Do you mind teach me how?

Nov
03
2 weeks ago
Activity icon

Started a new Conversation Calculate Total & Store It

Im trying to calculate the total. But I dont know where to start.

Formula:

shampoo: $22/unit - need to multiply with the number of quantity for shampoo balm: $28/unit - need to multiply with the number of quantity for balm

Eg record (below img) In the record, I inserted the total manually https://imgur.com/a/LSSDRHB

RestockController.php

    public function store(Request $request)
    {
        $request->validate([ 'quantity' => 'numeric|min:400']);

        $address = $request->input('address');
        $phone_no = $request->input('phone_no');
        $date = $request->input('date');
        $total = $request->input('total');

        $desc_shampoo = $request->input('desc_shampoo');
        $desc_balm = $request->input('desc_balm');
        $qty_shampoo = $request->input('qty_shampoo');
        $qty_balm = $request->input('qty_balm');

        $restock =  Restock::create(
            [
                'address' => $address,
                'phone_no' => $phone_no,
                'date' => $date,
                'total' => $total,
                'restock_user_id' => Auth::id(),
            ]
        );

        Unit::create(
            [
                'desc_shampoo' => $desc_shampoo,
                'desc_balm' => $desc_balm,
                'qty_shampoo' => $qty_shampoo,
                'qty_balm' => $qty_balm,
                'restock_id' => $restock->id,
            ]
        );

        //Create session to display Flash message
        Session::flash('add_restock_success', 'Successful added new restock!');

        return redirect()->back();
    }

Restock.php (model)

    public function user()
    {
        return $this->belongsTo('App\User', 'restock_user_id', 'id');
    }

    public function unit()
    {
        return $this->hasOne('App\Unit');
    }

Unit.php (model)

    public function restock()
    {
        return $this->belongsTo('App\Restock');
    }
Oct
23
3 weeks ago
Activity icon

Replied to Update Data

Thankyou @piljac1 for reminding me about the hasMany. I totally forgot to change it to hasOne. And it need to be hasOne. I already change all the coding and forgot this part :)

Activity icon

Replied to Update Data

@ahmeddabak it does not contain get()

    public function unit()
    {
        return $this->hasMany('App\Unit');
    }
Activity icon

Replied to Update Data

@ahmeddabak thank you for helping, but this error shows when i try it out

Method Illuminate\Database\Eloquent\Collection::update does not exist.

And if I do dd($request), it does have the value 555 in both quantity (i change both of it to 555)

+attributes: ParameterBag {#45 ▼
    #parameters: []
+request: ParameterBag {#44 ▼
    #parameters: array:10 [▼
      "_method" => "PATCH"
      "_token" => "1RF0ZAPzBpjT0xYjSG6SC3P0H23D0qDgbwL6mzHC"
      "address" => "lapangan"
      "phone_no" => "011-12345678"
      "date" => "2019-10-12"
      "desc_shampoo" => "Shampoo"
      "qty_shampoo" => "555"
      "desc_balm" => "Balm"
      "qty_balm" => "555"
      "total" => "RM 12,000"
    ]
  }
Activity icon

Replied to Update Data

But @nakov , if I use create, it will create a new record. I only want to update the current record .

I also tried this one for update but it looks wrong

$request->validate([ 'quantity' => 'numeric|min:400']);
$restock = Restock::findOrFail($id);

// Save all the input inside a new attributes
$address = $request->input('address');
$phone_no = $request->input('phone_no');
$date = $request->input('date');
$total = $request->input('total');

$desc_shampoo = $request->input('desc_shampoo');
$desc_balm = $request->input('desc_balm');
$qty_shampoo = $request->input('qty_shampoo');
$qty_balm = $request->input('qty_balm');

// Update
$restock->update(['address'=>$address]);
$restock->update(['phone_no'=>$phone_no]);
$restock->update(['date'=>$date]);
$restock->update(['total'=>$total]);
$restock->update(['restock_user_id' => Auth::id()]);

$restock->unit->update(['desc_shampoo'=>$desc_shampoo]);
$restock->unit->update(['desc_balm'=>$desc_balm]);
$restock->unit->update(['qty_shampoo'=>$qty_shampoo]);
$restock->unit->update(['qty_balm'=>$qty_balm]);
$restock->unit->update(['restock_id' => $restock -> id]);
Activity icon

Started a new Conversation Update Data

Quick question, this is my update method in controller. Is it correct? Is the "::insert" correct?

    $address = $request->input('address');
        $phone_no = $request->input('phone_no');
        $date = $request->input('date');
        $total = $request->input('total');

        $desc_shampoo = $request->input('desc_shampoo');
        $desc_balm = $request->input('desc_balm');
        $qty_shampoo = $request->input('qty_shampoo');
        $qty_balm = $request->input('qty_balm');

        $restock =  Restock::insert(
            [
                'address' => $address,
                'phone_no' => $phone_no,
                'date' => $date,
                'total' => $total,
                'restock_user_id' => Auth::id(),
            ]
        );

        Unit::insert(
            [
                'desc_shampoo' => $desc_shampoo,
                'desc_balm' => $desc_balm,
                'qty_shampoo' => $qty_shampoo,
                'qty_balm' => $qty_balm,
                'restock_id' => $restock->id,
            ]
        );
Oct
22
4 weeks ago
Activity icon

Replied to Retrieve Data From Database

@siangboon i have done the dd, and the $unit have value before pass it to the view. I already try to pass the data from database to edit blade, but its not working. What should i do

https://imgur.com/a/DBvvujk

This is my controller

public function edit(Restock $restock)
{
    $id = $restock->id;
    $restock = Restock::findOrFail($id);
    return view ('restock.edit', compact ('restock'));
}
Activity icon

Replied to Retrieve Data From Database

im sorry @woddell , but i did not understand what you are saying

Activity icon

Replied to Retrieve Data From Database

@tykus

maybe because the blade that i show you retrieve the data from other table. This is the full coding for edit.blade.php

<h1>Edit Restock Details</h1>
  
//------------------------------From table restock------------------------------------

{!! Form::model($restock, ['method' => 'PATCH', 'action' => ['[email protected]', $restock->id]]) !!}

{!! Form::label('address', 'Address:') !!}
{!! Form::text('address', null, ['class' => 'form-control', 'placeholder' => 'Address', 'required' => 'required']) !!}

{!! Form::label('phone_no', 'Phone Number:') !!}
{!! Form::text('phone_no', null, ['class' => 'form-control', 'placeholder' => 'Eg. 019-4568765', 'required' => 'required']) !!}

{!! Form::label('date', 'Date:') !!}
{!! Form::date('date', null, ['class' => 'form-control', 'placeholder' => 'Date', 'required' => 'required']) !!}

<h3>Item:</h3>

//--------------------------------From table unit-------------------------------------

<div class="form-group">
    <td>

        <form action="" method="POST">
            <div class="form-group" >
                <input type="hidden" name="desc_shampoo" id="desc_shampoo" value="Shampoo">
                <input type="text" name="desc_shampoo" value="Shampoo" id="desc_shampoo" disabled>
                <input type="number" name="qty_shampoo" placeholder="Quantity" value="{{ $unit->qty_shampoo }}" id="qty_shampoo" min="400" max="5000" >

            </div>

            <div class="form-group">
                <input type="hidden" name="desc_balm" id="desc_balm" value="Balm">
                <input type="text" name="desc_balm" value="Balm" id="desc_balm" disabled>
                <input type="number" name="qty_balm" placeholder="Quantity" value="{{ $unit->qty_balm }}" id="qty_balm" min="400" max="5000" >
            </div>
        </form>

//-------------------------------From table restock-----------------------------------

        {!! Form::label('total', 'Total (RM):') !!}
        {!! Form::text('total', null, ['class' => 'form-control', 'placeholder' => 'Total', 'required' => 'required']) !!}
        <br/>
        {!! Form::submit('Edit', ['class'=>'btn btn-primary btn-lg col-sm-12']) !!}
        {{--</div>--}}
        <hr>
        {!! Form::open (['method'=>'DELETE', 'action'=>['[email protected]', $restock->id]]) !!}

        <button type="submit" class="btn btn-danger btn-lg col-sm-12" onclick="return confirm('Are you sure want to delete?')">Delete</button>
        {{--        {!! Form::submit('Delete Group', ['class'=>'btn btn-danger btn-lg col-sm-12']) !!}--}}
        {!! Form::close() !!}
    </td>
</div>

Unit.php

public function restock()
    {
        return $this->belongsTo('App\Restock');
    }

Restock.php

public function unit()
    {
        return $this->hasMany('App\Unit');
    }
Activity icon

Replied to Retrieve Data From Database

@tykus , i already use the coding you suggested, but the quantity still not showing up

Activity icon

Started a new Conversation Retrieve Data From Database

I am new, this is maybe a basic knowledge, but if i do like below for my create, how can i retrieve the data in database for my edit.blade.php?

This is my create.blade.php

<form action="" method="POST">
    <div class="form-group" >
        <input type="hidden" name="desc_shampoo" id="desc_shampoo" value="Shampoo">
        <input type="text" name="desc_shampoo" value="Shampoo" id="desc_shampoo" disabled>
        <input type="number" name="qty_shampoo" placeholder="Quantity" id="qty_shampoo" min="400" max="5000" >
    </div>
    <div class="form-group">
        <input type="hidden" name="desc_balm" id="desc_balm" value="Balm">
        <input type="text" name="desc_balm" value="Balm " id="desc_balm" disabled>
        <input type="number" name="qty_balm" placeholder="Quantity" id="qty_balm" min="400" max="5000" >
    </div>
</form>
Oct
17
1 month ago
Activity icon

Started a new Conversation Numbering Other Than Increment

How to do the numbering other than by using this (below) ?

$table->increments('id');

Because i divided user by 2 role, admin and master stockist. When i want to display master stockist only, the numbering not "1 2 3" because of the increment.

https://imgur.com/a/o0og5bk

Is there any other way to do this?

Oct
16
1 month ago
Activity icon

Replied to Property [desc_shampoo] Does Not Exist On This Collection Instance.

is this correct?

    @if($mstrStockist)


                @foreach($mstrStockist as $ms)

                    <tr>

                        {{--Display no--}}
                        <td>{{$ms->id}}</td>

                        {{--Display name--}}
                        @if($ms->user)
                            <td><a href="{{route('restocks.edit', $ms)}}">{{$ms->user->name}}</a></td>
                        @endif

                        {{--Display ID--}}
                        @if($ms->user)
                            <td>{{$ms->user->user_id}}</td>
                        @endif

                        {{--Display address--}}
                        <td>{{$ms->address}}</td>

                        {{--Display phone no--}}
                        <td>{{$ms->phone_no}}</td>

                        {{--Display date--}}
                        <td>{{$ms->date}}</td>

                        {{--Desc Shampoo--}}
                        @foreach($ms->unit as $unit)
                            {{ $unit->desc_shampoo }}
                        @endforeach

                        {{--Qty Shampoo--}}
                        @foreach($ms->unit as $unit2)
                            {{ $unit2->qty_shampoo }}
                        @endforeach

                        {{--Desc Balm--}}
            @foreach($ms->unit as $unit1)
                            {{ $unit1->desc_balm }}
                        @endforeach

                        {{--Qty Balm--}}
                        @foreach($ms->unit as $unit3)
                            {{ $unit3->qty_balm }}
                        @endforeach

                        {{--Display total--}}
                        <td>{{$ms->total}}</td>

                    </tr>

                @endforeach

    @endif

Besides, do you perhaps know why some of the data not being stored in database? it display null https://imgur.com/a/NBcA9MR

Activity icon

Started a new Conversation Property [desc_shampoo] Does Not Exist On This Collection Instance.

i have this error while trying to viewing my index. mind helping?

controller

public function index()
    {
        $userId = Auth::user()->id;

        $restock = Restock::all();
        $mstrStockist = Restock::where('restock_user_id',$userId)->get();
        
//      already tried this, but still not working
//        $mstrStockist = Restock::where('restock_user_id',$userId)->first();

        return view('masterStockist.index',compact('mstrStockist', 'userId', 'restock'));
    }


    public function store(Request $request)
    {

        $request->validate([ 'quantity' => 'numeric|min:400']);

        $address = $request->input('address');
        $phone_no = $request->input('phone_no');
        $date = $request->input('date');
        $total = $request->input('total');

        $desc_shampoo = $request->input('desc_shampoo');
        $desc_balm = $request->input('desc_balm');
        $qty_shampoo = $request->input('qty_shampoo');
        $qty_balm = $request->input('qty_balm');

        $restock =  Restock::create(
            [
                'address' => $address,
                'phone_no' => $phone_no,
                'date' => $date,
                'total' => $total,
                'restock_user_id' => Auth::id(),
            ]
        );

        Unit::create(
            [
                'desc_shampoo' => $desc_shampoo,
                'desc_balm' => $desc_balm,
                'qty_shampoo' => $qty_shampoo,
                'qty_balm' => $qty_balm,
                'restock_id' => $restock->id,
            ]
        );

        //Create session to display Flash message
        Session::flash('add_restock_success', 'Successful added new restock!');

        return redirect()->back();

    }

blade

    <h1 style="text-align:center;">Restock</h1>
    <div class="col-md-12">

        <table id="laravel_datatable" class="table table-bordered" >
            <thead>
            <tr>
                <th>No.</th>
                <th>Name</th>
                <th>ID</th>
                <th>Address</th>
                <th>Phone Number</th>
                <th>Date</th>
                <th>Description</th>
                <th>Quantity</th>
                <th>Description</th>
                <th>Quantity</th>
                <th>Total (RM)</th>

            </tr>
            </thead>
            <tbody>


            @if($mstrStockist)


                @foreach($mstrStockist as $ms)

                    <tr>

                        {{--Display no--}}
                        <td>{{$ms->id}}</td>

                        {{--Display name--}}
                        {{--<td><a href="{{route('restocks.edit', $restock)}}">{{$restock->name}}</a></td>--}}
                        @if($ms->user)
                            <td><a href="{{route('restocks.edit', $ms)}}">{{$ms->user->name}}</a></td>
                        @endif

                        {{--Display ID--}}
                        @if($ms->user)
                            <td>{{$ms->user->user_id}}</td>
                        @endif

                        {{--Display address--}}
                        <td>{{$ms->address}}</td>

                        {{--Display phone no--}}
                        <td>{{$ms->phone_no}}</td>

                        {{--Display date--}}
                        <td>{{$ms->date}}</td>

                        {{--Desc Shampoo--}}
                        @if($ms->unit)
                            <td>{{$ms->unit->desc_shampoo}}</td>
                        @endif

                        {{--Desc Balm--}}
                        @if($ms->unit)
                            <td>{{$ms->unit->desc_balm}}</td>
                        @endif

                        {{--Qty Shampoo--}}
                        @if($ms->unit)
                            <td>{{$ms->unit->qty_shampoo}}</td>
                        @endif

                        {{--Qty Balm--}}
                        @if($ms->unit)
                            <td>{{$ms->unit->qty_balm}}</td>
                        @endif

                        {{--Display total--}}
                        <td>{{$ms->total}}</td>

                    </tr>

                @endforeach

            @endif


            </tbody>
        </table>
    </div>

restock model

class Restock extends Model
{
    protected $fillable = [
    'restock_user_id',
    'address',
    'phone_no',
    'date',
    'total'
];

    public function user()
    {
//        return $this->belongsTo('App\User');
        return $this->belongsTo('App\User', 'restock_user_id', 'id');
    }

    public function unit()
    {
        return $this->hasMany('App\Unit');
    }
}
Oct
15
1 month ago
Activity icon

Replied to How To Group 2 Attributes Under 1 Id (create)

@sinnbeck

Can you explain this coding for me? I did not understand it.

foreach ($request->item_name as $key =>$name) 
{
    $item = resolve(Item::class);
    $item->item_name = $name;        
    $item->qty = $request->qty[$key] ;    
    $item->unit_price = $request->unit_price[$key] ; 
    $item->save();
} 
Activity icon

Replied to How To Group 2 Attributes Under 1 Id (create)

@rameezisrar

alrightt.

This is the view for my form https://imgur.com/a/lWqwgaU

but i have some problem with controller. I need to loop the Unit::create

do you perhaps know how to do it?

Because it only save the data for the shampoo part.

Activity icon

Replied to Column Not Found

@siangboon , I decide to keep the restock_id. Sorry to trouble you,

but i have some problem with controller. I need to loop the Unit::create

do you perhaps know how to do it?

Because it only save the data for the shampoo part. https://imgur.com/a/lWqwgaU

public function store(Request $request)
    {

        $request->validate([ 'quantity' => 'numeric|min:400']);

        $address = $request->input('address');
        $phone_no = $request->input('phone_no');
        $date = $request->input('date');
        $total = $request->input('total');

        $description = $request->input('description');
        $quantity = $request->input('quantity');

        $restock =  Restock::create(
            [
                'address' => $address,
                'phone_no' => $phone_no,
                'date' => $date,
                'total' => $total,
                'restock_user_id' => Auth::id(),
            ]
        );

        Unit::create(
            [
                'description' => $description,
                'quantity' => $quantity,
                'restock_id' => $restock->id,
            ]
        );

        //Create session to display Flash message
        Session::flash('add_restock_success', 'Successful added new restock!');

        return redirect()->back();

    }
Activity icon

Replied to Submit Button Not Function

Already solve this, i need to move the submit button into the form.

Oct
14
1 month ago
Activity icon

Replied to Column Not Found

@siangboon

This is my Restock model

    public function user()
    {
//        return $this->belongsTo('App\User');
        return $this->belongsTo('App\User', 'restock_user_id', 'id');
    }

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

Im sorry, im trying to solve many error at the same time

Activity icon

Replied to Submit Button Not Function

@munazzil still nothing change :(