FareedR

FareedR

Member Since 11 Months Ago

Experience Points 5,360
Experience Level 2

4,640 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 14
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

02 Jun
2 weeks ago

FareedR left a reply on Contact Us Form

i solved it and it works . I think subject() is deprecated . when i remove it, everything is ok .

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class SendEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $message,$subject;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($from,$subject,$message)
    {
        $this->from($from);
        $this->subject = $subject;
        $this->message = $message;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.guest.contact')
                    ->with([
                        'subjects' => $this->subject,
                        'messages' => $this->message,
                    ]);
    }
}

FareedR left a reply on Contact Us Form

in my use case , system admin should receive an email from guest in Contact Us page .

FareedR left a reply on Contact Us Form

value for $from is "sender" . and the recipient is system admin .

FareedR left a reply on Contact Us Form

@JOHNBRAUN - this is my view code

<p>
Message: {{ $message }}
</p>

FareedR left a reply on Contact Us Form

@JOHNBRAUN - its happen on this code because i try dd before & after return process . first dd come out but 2nd dd throw the error that i gave just now.

dd('example1');
return $this->subject($subject)
                    ->from($from)
                    ->to('[email protected]')
                    ->view('emails.guest.contact')
                    ->with([
                        'message' => $this->message
                    ]);
dd('example2');

FareedR left a reply on Contact Us Form

@JOHNBRAUN - sorry for the late reply . error that i get stated below

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
[] operator not supported for strings
01 Jun
2 weeks ago

FareedR started a new conversation Contact Us Form

why i keep receive this error ? i'm using php artisan make:mail & i'm using mailtrap for testing email. do i need a real domain to test the email?

//error
protected function setAddress($address, $name = null, $property = 'to')
    {
        foreach ($this->addressesToArray($address, $name) as $recipient) {
            $recipient = $this->normalizeRecipient($recipient);
 
            $this->{$property}[] = [
                'name' => $recipient->name ?? null,
                'address' => $recipient->email,
            ];
        }
 
        return $this;
    }

this is my code

// controller
    public function sendEmail(SendEmailFormRequest $request)
    {
        $from = $request->get('email');
        $subject = $request->get('subject');
        $message = $request->get('message');
    // will pass to SendEmail.php
        Mail::send(new SendEmail($from,$subject,$message));
    }
// sendemail.php
class SendEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $email;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($from,$subject,$message)
    {
        $this->from = $from;
        $this->subject = $subject;
        $this->message = $message;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $from = $this->from;
        $subject = $this->subject;
        
        return $this->subject($subject)
                    ->from($from)
                    ->to('[email protected]')
                    ->view('emails.guest.contact')
                    ->with([
                        'message' => $this->message
                    ]);
    }
}
16 May
1 month ago

FareedR started a new conversation Update Data With Current Image File Using Same Form Request From Store Function

how can i use same form request on update function ? it keep display to me " Image field is required " but i dont want to update image , i just want to update other data only . not image .

// form request
public function rules()
    {
        return [
            'title' => 'required|min:6',
            'image' => 'required|image|mimes:png|dimensions:width=1920,height=1076',
            'description' => 'required|min:6',
            'status' => 'required'
        ];
    }
//controller
 public function updateBanner(BannerFormRequest $request,$id)
    {
        $banner = Banner::findOrFail($id);

        if($request->hasFile('image')){
            $oldImage = Storage::disk('public')->delete('{{ $banner->image }}');
            $image = $request->file('image')->store('banners','public');
        }

        $banner->title = $request->get('title');
        $banner->description = $request->get('description');
        $banner->status = $request->get('status');
        $banner->save();

        toastr()->success('Banner has been updated');
        return redirect()->route('list-banner');
    }
//blade
<div class="block-content">
            <form action="{{ route('update-banner', $banner->id) }}" method="post" enctype="multipart/data">
            @csrf
            @method('PATCH')
                <div class="form-group">
                    <label for="input-title">Title</label>
                    <input type="text" class="form-control" name="title" value="{{ $banner->title }}">
                </div>
                <div class="form-group">
                    <label for="input-image">Image</label>
                    <input type="file" class="form-control" name="image">
                    <div class="img">
                        <img class="img-fluid" style="width:50%" src="{{ Storage::url($banner->image) }}">
                    </div>
                </div>
                <div class="form-group">
                    <label for="input-description">Description</label>
                    <input type="text" class="form-control" name="description" value="{{ $banner->description }}">
                </div>
                <div class="form-group">
                    <label for="input-status">Status</label>
                    <select name="status" class="form-control">
                        @if($banner->status)
                        <option value="0">Inactive</option>
                        <option value="1" selected>Active</option>
                        @else
                        <option value="0" selected>Inactive</option>
                        <option value="1">Active</option>
                        @endif
                    </select>
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-alt-primary">Submit</button>
                </div>
            </form>
        </div>
04 May
1 month ago

FareedR left a reply on What Should I Response In Login Process ?

@TISUCHI - currently i'm using it .

FareedR left a reply on What Should I Response In Login Process ?

@tisuchi @roborobok i think i let my API like this . make sense ?

//api routes
Route::post('/login','API\V1\Auth\[email protected]')->name('login');

Route::prefix('student')->middleware(['auth:api','role:student'])->group(function(){
    Route::get('/','API\V1\Student\[email protected]')->name('view-home-student');
});

//auth controller
public function login(Request $request)
    {
        $request->validate([
            'id_no' => 'required|string',
            'password' => 'required|string'
        ]);

        $credentials = request(['id_no','password']);

        // Check credentials
        if(!Auth::attempt($credentials)){
            return response()->json([
                'message' => 'Unauthorized'
            ],401);
        }else{
            $user = $request->user();

            // Create user token
            $tokenResult = $user->createToken('Personal Access Token');
            $token = $tokenResult->token;
            $token->save();
            
            return response()->json([
                'message' => 'Successfully Login'
            ],201);
            
        }
    }

//student controller
public function home(Request $request)
    {
        $user = $request->user()

        return response()->json([
            // User
            'student_id' => $user->id_no,
            // Campus
            'campus_name' => $user->campus->name,
            // Profile
            'student_name' => $user->students()->first()->name,
            'student_id' => $user->students()->first()->id,
            'avatar' => $user->students()->first()->profile->avatar,
        ],201);
    }

FareedR left a reply on What Should I Response In Login Process ?

which one do i need to do ? what i understanding is , endpoint is giving the data to the view . but in my case . i just need to check if user valid and has student role , then user can see all the club in mobile app.

controller 
    if($user->hasRole('student')){
                $club = Club::all();
                return response()->json([
                    'access_token' => $tokenResult->accessToken,
                    'token_type' => 'Bearer',
                    'user' => $user,
                    'club' => $club
                ],201);
            }

or

api.php
Route::prefix('student')->middleware(['auth:api','role:student'])->group(function(){
    Route::get('view-home-student','API\V1\Student\[email protected]')->name('view-home-student');
});

controller
//auth controller
    if($user->hasRole('student')){
                return redirect('/student');
            }

//student controller
public function home(Request $request)
    {
        $user = $request->user();
        $club = Club::all();
        return response()->json([
            'user' => $user,
            'club' => $club
        ],201);
    }

FareedR left a reply on What Should I Response In Login Process ?

@ROBOROBOK - yup it's SPA . basically, at this point , i just want to check if user valid and has student role, then user have the right to view as student and list of club . do i need to make one more endpoint just to retrieve user info and club info ?

FareedR started a new conversation What Should I Response In Login Process ?

I'm doing API right now . what should i response if user exist and has that role because if in web, we just redirect it to folder . how about in API ? should do the same thing or just return response success ? p/s first time developing an API

class LoginController extends Controller
{
    public function login(Request $request)
    {
        $request->validate([
            'id_no' => 'required|string',
            'password' => 'required|string'
        ]);

        $credentials = request(['id_no','password']);

        // Check credentials
        if(!Auth::attempt($credentials)){
            return response()->json([
                'message' => 'Unauthorized'
            ],401);
        }else{
            $user = $request->user();

            // Create user token
            $tokenResult = $user->createToken('Personal Access Token');
            $token = $tokenResult->token;
            $token->save();
            
            if($user->hasRole('student')){
                return response()->json([
                    'access_token' => $tokenResult->accessToken,
                    'token_type' => 'Bearer',
                    'user' => $user
                ],201);
            }
        }
    }
}
03 May
1 month ago

FareedR left a reply on Pass Current Id And Date From Table Submit Button

// blade
<td> 
    <form action = {{ route('anything', $user->id) }}>
    @csrf
        <input type="date" name="startdate">
        <button type="submit">Submit</submit>
    </form>
</td>

// controller
public function anything(Request $request,$id)
{
    $request->get('start_date');
}

FareedR started a new conversation Play Around With API

Currently digging deeper in API and i play around with simple auth process . My question is do i need to make function logout for each role ( in future ) for example , i have 3 role . so do i need to implement the same function logout into each role ? Based on my understanding, API are playing with token right ? so it doesnt same like web which is we can call " auth()->user()->id " .

Route::post('/login','API\V1\Auth\[email protected]')->name('login');
Route::post('/register','API\V1\Auth\[email protected]')->name('register');

Route::prefix('user')->middleware('auth:api')->group(function(){
    Route::get('/logout','API\V1\Auth\[email protected]')->name('logout');
    Route::get('user-profile/{id}','API\V1\User\[email protected]')->name('view-user-profile');
    Route::post('update-user-profile/{id}','API\V1\User\[email protected]')->name('update-user-profile');
});
30 Apr
1 month ago

FareedR left a reply on How Can I Get {id} From Url ?

its done and thank you for helping me !

// compact the id in controller and pass it to view as below 
<form action="{{ route('store-venue-superadmin', $id ) }}" method="post">

// return view after store with following code 
return redirect()->route('view-list-venue-superadmin',['id' => $id]);

FareedR left a reply on How Can I Get {id} From Url ?

@JLRDW - how can I keep {5} to other view ?

FareedR started a new conversation How Can I Get {id} From Url ?

web.php
 Route::get('/list-venue/{id}','Superadmin\[email protected]');
 Route::get('/create-venue/{id}','Superadmin\[email protected]');

controller
public function listVenue($id)
    {
        $venues = Venue::where('campus_id',$id)->get();

        return view('superadmin.venues.index',compact('venues'));
    }

// retrieve id from function above . 

 public function storeVenueForm( Request $request,$id)
    {
        $venue = new Venue ([
            'campus_id' => $id,
            'name' => $request->get('name'),
            'status' => $request->get('status')
        ]);

        $venue->save();

29 Apr
1 month ago

FareedR left a reply on Getting Data Using With() Relation In Controller To Js

@TALINON - thankyou ! it works for me . new knowledge for me regarding to '->' things . thanks again !

FareedR left a reply on Getting Data Using With() Relation In Controller To Js

@TOMI - yup . i've done it . i got a relation "campuses" full with data . but when put it as "campusObj.campuses->id" . it didnt display anything .

https://imgur.com/QSKqxRx

FareedR started a new conversation Getting Data Using With() Relation In Controller To Js

How can i get campus data ?

// db
universities
id | subdomain |

campus
id | university_id | name |

// script
<script>
            $('#btnSearch').on('click',function (event){
        // getting subdomain here
                var university = $('#university').val()
                $.ajax({
                    type: "GET",
                    url: "{{ url('/get-university') }}" + '/' + university,
                    data: {university : university},
                    success: function(data){
                        $('#availableCampus').empty()
                        $.each(data,function(index, campusObj){
                            $('#availableCampus').append('<option value="{{'+campusObj.id+'}}">'+campusObj.name+ '</option>')
                        });
                    },
                    error: function(){
                        swal({
                            title: "Opps",
                            text: "University doesnt exist",
                            icon: "error",
                            timer: 1500
                        })
                    }
                })
            });
        </script>

//controller
27 Apr
1 month ago

FareedR left a reply on Send File On Modal Using AJAX

@FTIERSCH - oh ya ! it's my mistake . thankyou !

FareedR left a reply on Send File On Modal Using AJAX

@CRONIX - i've tried his tutorial . file transfer is working but i didnt get event_id from "var event" when i click the button submit .i've tried input type "submit & button type button . the result is same . url that i get is "/club/upload-document-event-club/object Object"

view
<button type="button" class="btn btn-sm btn-rounded btn-warning" data-toggle="modal" data-target="#modal-normal" data-event="{{ $event->id }}" title="Upload Document">
    Upload Approval Document
</button>


<div class="modal" id="modal-normal" tabindex="-1" role="dialog" aria-labelledby="modal-normal" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <form id="form" method="post" enctype="multipart/form-data">
            @csrf
                <div class="block block-themed block-transparent mb-0">
                    <div class="block-header bg-primary-dark">
                        <h3 class="block-title">Upload Approval Document</h3>
                        <div class="block-options">
                            <button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
                                <i class="si si-close"></i>
                            </button>
                        </div>
                    </div>
                    <div class="block-content">
                        <input type="file" class="form-control" id="file" name="supported_document">
                        <span class="text-danger"> PDF FILE ONLY </span>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-alt-secondary" id="uploadApprovalDocument">Submit</button>
                    <!-- <input type="submit" class="btn btn-alt-success" id="uploadApprovalDocument" value="Submit">  -->
                </div>
            </form>
        </div>
    </div>
</div>

script
$('#modal-normal').on('show.bs.modal', function(e){
        var button = $(e.relatedTarget)
        var event = button.data('event')
        var modal = $(this)
    
    // i still get the ID from button . 
        console.log('before',event);

        // button to click for submit form inside modal
        $('#uploadApprovalDocument').on('click', function(event){
            // i lost the ID when i click that button
        console.log('after',event);
            // stop submit form natively. 
            event.preventDefault();
            var form = $('#form')[0];
            var data = new FormData(form);
            swal({
                title:"Are you sure this is correct file to submit?",
                text:"Once submit, you can't change the file",
                icon: "warning",
                dangerMode: true,
            })
            .then((willUpload) => {
                if (willUpload) {
                        // if TRUE, send input file to controller based on eventID
                        $.ajax({
                        type: "POST",
                        enctype: "multipart/form-data",
                        url: "{{ url('/club/upload-document-event-club') }}" + '/' + event,
                        data: data,
                        processData: false,
                        contentType: false,
                        cache: false,
                        success: function(){
                            console.log('posted',event);
                            console.log(data);
                            swal({
                            title: "Approval Document has been sent!",
                            text: "Click OK to refresh the page",
                            icon: "success",
                            }).then(function(){
                                location.reload();
                            });
                        },
                        error : function(e){
                            console.log(e);
                            swal({
                                title: "Opps...",
                                text : "Something wrong occured",
                                icon: "error",
                                timer: 1500
                            })
                            }
                        })
                }else{
                    swal("Nothing happens here");
                }
            });
        })
    });
26 Apr
1 month ago

FareedR left a reply on Send File On Modal Using AJAX

@FTIERSCH - i really lost right now . i can't think anything . thankyou for you reply btw .

FareedR started a new conversation Send File On Modal Using AJAX

i guess i'm missing something in ajax posting, but i couldn't figure it out

 <button type="button" class="btn btn-sm btn-rounded btn-warning" data-toggle="modal" data-target="#modal-normal" data-event="{{ $event->id }}" title="Upload Document">
    Upload Approval Document
</button>

// Modal that trigger button above
<div class="modal" id="modal-normal" tabindex="-1" role="dialog" aria-labelledby="modal-normal" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="block block-themed block-transparent mb-0">
                <div class="block-header bg-primary-dark">
                    <h3 class="block-title">Upload Approval Document</h3>
                    <div class="block-options">
                        <button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
                            <i class="si si-close"></i>
                        </button>
                    </div>
                </div>
                <div class="block-content">
                    <form id="form" method="post" enctype="multipart/form-data">
                    @csrf
                        <input type="file" class="form-control" id="file" name="supported_document">
                        <span class="text-danger"> PDF FILE ONLY </span>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-alt-success" id="uploadApprovalDocument">
                    <i class="fa fa-check"></i> Submit
                </button>
            </div>
        </div>
    </div>
</div>

// script that used for modal
<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    // Trigger data-target modal 
    $('#modal-normal').on('show.bs.modal', function(e){
        var button = $(e.relatedTarget)
        var event = button.data('event')

        var modal = $(this)
        
        // button to click for submit form inside modal
        $('#uploadApprovalDocument').on('click', function(){
            // catch data input file 
            $('#form').submit(function(event){
                var file = new FormData($(this)[0]);
            })
            swal({
                title:"Are you sure this is correct file to submit?",
                text:"Once submit, you can't change the file",
                icon: "warning",
                dangerMode: true,
            })
            .then((willUpload) => {
                if (willUpload) {
                        // if TRUE, send input file to controller based on eventID 
                        $.ajax({
                        url : "{{ url('/club/upload-document-event-club') }}" + '/' + event,
                        type : "POST",
                        data : {'_method' : 'POST', 'supported_document' : 'file'},
                        success: function(){
                            swal({
                                title: "Success",
                                text: "Approval Document has been sent! \n Click OK to refresh the page",
                                icon: "success",
                                }).then(function(){
                                location.reload();
                                });
                        },
                        error : function(){
                            swal({
                                title: "Opps...",
                                text : "Something wrong occured",
                                icon: "error",
                                timer: 1500
                            })
                            }
                        })
                }else{
                    swal("Nothing happens here");
                }
            });
        })
    });
</script>
25 Apr
1 month ago

FareedR started a new conversation Checking Multiple Table For Unique Validation

i separate table by their role. how can i check their email has been taken or not & how can i update same user with same email address ? can i just put ignore('$user->id') ?

'email' => 'required|unique:superadmins,email|unique:admins,email|unique:lecturers,email|unique:students,email',

FareedR left a reply on Validation On Required_if

@BRAUNSON - it works for me , thankyou @braunson ! can i ask you in the same question about image validation on update method ? what if user need to update name and address only but in the form , banner image is there . what should i put in FormRequest? do i need to put input hidden to trigger whether true or false ?

'banner' => 'bail|required_unless=has_file,=,0|mimes:jpeg,png|dimensions:width=1920,height=1080',

23 Apr
1 month ago

FareedR started a new conversation Validation On Required_if

how can i ignore "amount" IF "fee" = 2 ? i keep getting rule for integer on "amount" . do i need to use bail or something else ?

'fee' => 'required',
'amount' => 'required_if:fee,=,1|integer|gte:1',

FareedR left a reply on How To Prevent From This Javascript From Load ?

@CRONIX - it works for me . thankyou @cronix

$(document).ready(function(){
    var start ;
    var end ;
    $('#startDate').on("change",function(){
        start = $(this).val();
        getDate();
    });
    $('#endDate').on("change",function(){
        end = $(this).val();
        getDate();
    });

    function getDate(){
        // if we have start date AND end date value then do ajax inside it
        if(start && end){
            // ajax code here
                $.ajax({
                type : "GET",
                url : "{{ url('club/available-venue-club/start') }}" + '/' + start + '/end/' + end ,
                data :  {'start' : start,'end' : end },
                success : function (data){
                    $('#availableVenue').empty();
                    $.each(data, function(index, venueObj){
                        $('#availableVenue').append('<option value="'+venueObj.id+'">'+venueObj.name+'</option>');
                    });
                } 
            }); 
        }
    }
})

FareedR left a reply on How To Prevent From This Javascript From Load ?

@SAFEMOOD - i put it on $('#endDate') . it is okay ? what if user change startDate only to recheck the venue ?

$(document).ready(function(){
    var start ;
    var end ;
    $('#startDate').on("change",function(){
        start = $(this).val();
    });
    $('#endDate').on("change",function(){
        end = $(this).val();
        $.ajax({
            type : "GET",
            url : "{{ url('club/available-venue-club/start') }}" + '/' + start + '/end/' + end ,
            data :  {'start' : start,'end' : end },
            success : function (data){
                $('#availableVenue').empty();
                $.each(data, function(index, venueObj){
                    $('#availableVenue').append('<option value="'+venueObj.id+'">'+venueObj.name+'</option>');
                });
            } 
        });
    });
})

FareedR started a new conversation How To Prevent From This Javascript From Load ?

input type = date

$(document).ready(function(){
    var start ;
    var end ;
    $('#startDate').on("change",function(e){
        e.preventDefault();
        start = $(this).val();
    });
    $('#endDate').on("change",function(f){
        f.preventDefault();
        end = $(this).val();
    });
    $.ajax({
        type : "GET",
        url : "{{ url('club/available-venue-club/start') }}" + '/' + start + '/end/' + end ,
        data :  {'start' : start,'end' : end },
        success : function (data){
            $('#availableVenue').empty();
            $.each(data, function(index, venueObj){
                $('#availableVenue').append('<option value="'+venueObj.id+'">'+venueObj.name+'</option>');
            });
        } 
    });
})
22 Apr
1 month ago

FareedR started a new conversation Achieve Available Venue On That Date.

i try to achieve "mini stadium" but collection still appear "stadium" and "mini stadium". should i use first() or get() ? or my query are wrong ? anyone can show me ?

database 
Venue
id | name |
1   stadium
2   mini stadium

Venue_has_bookings
id | venue_id | start_date | end_date|
1   1          2019-04-21   2019-04-25

controller
$startDate = 2019-04-21;
        $endDate = 2019-04-25;
        $availableVenue = Venue::with(['bookings' => function ($query) use ($startDate,$endDate){
            $query->where('endDate','>',$startDate)->where('startDate','>',$endDate)
            ->orWhere('endDate','<',$startDate)->where('startDate','<',$endDate);
        }])->get();
        dd($availableVenue);

FareedR started a new conversation How Can Simplify Condition Based On Role

What i want to achieve is

1) Button "unassign as President" only for user has role President
2) Button " unassign as Secretary" only for use has role Secretary
3) If president_id empty , display button "Assign as President" . if user has role Secretary, the button will hide.
4) if secretary_id empty , display button "Assign as Secretary". if user has role President , the button will hide .

Note that, 1 user have one role only . I attached blade view below. The user currently has role as President
@if(!empty($member->club->president_id && $member->student->user->hasRole('president') && !$member->student->user->hasRole('secretary') ))
                            <button type="button" class="btn btn-sm btn-rounded btn-primary" data-toggle="tooltip" title="Unassign as President" onclick="unassignPresident({{ $member->student_id }})">
                                Unassign as President
                            </button>
                        @else
                            <button type="button" class="btn btn-sm btn-rounded btn-info" data-toggle="tooltip" title="Assign as Secretary" onclick="assignSecretary({{ $member->student_id }})">
                                Assign as President
                            </button>
                        @endif
                        @if(!empty($member->club->secretary_id && $member->student->user->hasRole('secretary') && !$member->student->user->hasRole('president') ))
                            <button type="button" class="btn btn-sm btn-rounded btn-primary" data-toggle="tooltip" title="Unassign as President" onclick="unassignPresident({{ $member->student_id }})">
                                Unassign as Secretary
                            </button>
                        @else
                            <button type="button" class="btn btn-sm btn-rounded btn-info" data-toggle="tooltip" title="Assign as Secretary" onclick="assignSecretary({{ $member->student_id }})">
                                Assign as Secretary
                            </button>
                        @endif

https://imgur.com/tZW0efe

21 Apr
1 month ago

FareedR left a reply on Getting "Trying To Get Property Of Non-object" In Blade View.

@SNAPEY - oh okay , thankyou snapey for the info ! i appreciate it !

FareedR left a reply on Getting "Trying To Get Property Of Non-object" In Blade View.

@SNAPEY - i believe that if im using optional, my code would be like this ?

optional($club->president)->name or optional($club->president->name)->id

FareedR left a reply on Getting "Trying To Get Property Of Non-object" In Blade View.

@SNAPEY - i mislooked the code . i should put

@if(!empty($club->president_id))
                        <td class="text-center">
                            <span class="badge badge-primary">{{ $club->president->name }}</span>
                        </td>
                        @else
                        <td></td>
                        @endif

my mistake :(

FareedR left a reply on Getting "Trying To Get Property Of Non-object" In Blade View.

@ASHRAAM - actually in blade i use foreach to list down all the club . sorry for not mention it earlier .

FareedR started a new conversation Getting "Trying To Get Property Of Non-object" In Blade View.

I did test of my relation in laravel tinker . i get what i want . but in blade , i get an error for it . is there anything that i do wrong ?

<td class="text-center">
    <span class="badge badge-warning">{{ $club->president->name }}</span>
</td>
          
Relation in Club Model 
         
public function president()
    {
        return $this->belongsTo(Student::class,'president_id','id');
    }           

FareedR left a reply on How Can I Update Data From Relation ?

@TYKUS - thank you for response ! it works . thanks again . i've been stuck here like 3 hours ..

FareedR started a new conversation How Can I Update Data From Relation ?

how can I set data in club->president_id from member ? in database didnt update but alert appear success .

public function assignPresident($id)
    {
        $role = Role::find(5);
        $member = Member::with('club')->where('student_id',$id)->get()->first();
        $member->club->president_id = $id;
        
        $user = $member->student->user;
        $user->assignRole($role);

        $member->save();

    }

FareedR left a reply on Input Hidden Cant Achieve In Modal Javascript

@CRONIX - I've tried bootstrap docs . but i cant get the second id for club . how can i get club id using selection list in modal ?

<div class="modal" id="modal-large" tabindex="-1" role="dialog" aria-labelledby="modal-large" aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="block block-themed block-transparent mb-0">
                <div class="block-header bg-primary-dark">
                    <h3 class="block-title">Available Club</h3>
                    <div class="block-options">
                        <button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
                            <i class="si si-close"></i>
                        </button>
                    </div>
                </div>
                <div class="block-content">
                    <select name="club_id" id="club_id" class="form-control">
                        <option value="">--Please Select Club--</option>
                        @foreach($clubs as $club)
                        <option value="{{ $club->id }}">{{ $club->name}}</option>
                        @endforeach
                    </select>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-alt-success" onclick="assignAdviser()">
                    <i class="fa fa-check"></i> Assign
                </button>
            </div>
        </div>
    </div>
</div>
javascript
$('#modal-large').on('show.bs.modal', function(event){
        var button = $(event.relatedTarget)
        var lecturer = button.data('lecturer')

        var modal = $(this)
        var club = modal.find('.block-content select').val()
    })
18 Apr
2 months ago

FareedR left a reply on Input Hidden Cant Achieve In Modal Javascript

@SNAPEY - i put the modal inside foreach , is it okay ? if i use this method, it works for me . is there any other method ?

<div class="modal-footer">
                                            <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                                            <button type="button" class="btn btn-alt-success" onclick="assignAdviser({{$club->id}})">
                                                <i class="fa fa-check"></i> Assign
                                            </button>
                                        </div>

FareedR started a new conversation Input Hidden Cant Achieve In Modal Javascript

i put input hidden for id at below foreach . when i call modal to popup . it cant define where the id is . view

@foreach($clubs as $club)
                <input type="hidden" id="club_id" value="{{ $club->id }}">
                    <tr>
                        <td class="text-center">{{ $i++ }}</td>
                        <td class="font-w600">
                            <a href="" class="btn btn-primary">{{ $club->name }}</a>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-primary">{{ $club->adviser_id }}</span>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-warning">{{ $club->president_id }}</span>
                        </td>
                        <td class="text-center">
                            <span class="badge badge-info">{{ $club->secretary_id }}</span>
                        </td>
                        <td class="text-center">
                            @if($club->status == 1)
                                <span class="badge badge-primary">Active</span>
                            @else
                                <span class="badge badge-danger">Inactive</span>
                            @endif
                        </td>
                        <td class="text-center">
                            @if(empty($club->adviser_id))
                                <button type="button" class="btn btn-sm btn-rounded btn-warning" data-toggle="modal" data-target="#modal-fadein" title="Assign Adviser">
                                    Assign Adviser
                                </button>
                            @endif
                            <button type="button" class="btn btn-sm btn-rounded btn-info" data-toggle="tooltip" title="Review Club Profile">Review Club
                            </button>
                            <a href ="{{ route('view-edit-club-university',$club->id ) }}"class="btn btn-sm btn-rounded btn-primary" data-toggle="tooltip" title="Edit Club Profile">
                                Edit Club
                            </a>
                        </td>
                    </tr>
                @endforeach

modal

<div class="block block-themed block-transparent mb-0">
                    <div class="block-header bg-primary-dark">
                        <h3 class="block-title">Available Adviser</h3>
                        <div class="block-options">
                            <button type="button" class="btn-block-option" data-dismiss="modal" aria-label="Close">
                                <i class="si si-close"></i>
                            </button>
                        </div>
                    </div>
                    <div class="block-content">
                        <label>Adviser Name</label>
                        <select name="id" id="adviser_id" class="form-control">
                            <option value="0">--Choose Adviser--</option>
                        @foreach($advisers as $adviser)
                            <option value="{{ $adviser->id }}">{{ $adviser->name }}</option>
                        @endforeach
                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-alt-secondary" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-alt-success" onclick="assignAdviser()">
                        <i class="fa fa-check"></i> Assign
                    </button>
                </div>

javascript

function assignAdviser(){
       var club_id = $('#club_id').val();
       var adviser_id = $('#adviser_id').val();
       console.log(club_id);
       swal({
           title: "Are you sure to assign this adviser?",
           icon: "warning",
           buttons: true,
           dangerMode: true,
       })
       .then((willAssign) => {
           if (willAssign) {
                $.ajax({
                   url : "{{ url('/assign-adviser-club') }}" + '/club/' + club_id + '/adviser/' + adviser_id,
                   type : "POST",
                   success: function(){
                       swal({
                           title: "Success",
                           text: "Adviser has been assigned! \n Click OK to refresh the page",
                           icon: "success",
                        }).then(function(){
                           location.reload();
                        });
                   },
                   error : function(){
                       swal({
                           title: "Opps...",
                           text : "Something wrong occured",
                           icon: "error",
                           timer: 1500
                       })
                    }
               })
           }else{
               swal("Nothing happen here");
           }
       });
    }

FareedR left a reply on HasManyThrough 3 Table .

@STAUDENMEIR - this is new for me ! thank you !

17 Apr
2 months ago

FareedR started a new conversation HasManyThrough 3 Table .

how can I achieve list of student in from university through campus .

db structure 

universities
id
name

campuses
id 
university_id
name

users
id
campus_id

students
id
user_id

16 Apr
2 months ago

FareedR started a new conversation Override Login Authentication

how can i override login process . basically , laravel validate email and password . in my case , i need to validate student_id and password. anyone can help me ?

09 Apr
2 months ago

FareedR started a new conversation Image Validation During Update

I'm using FormRequest . how can I bail if user didnt want to update their image during edit .

FormRequest
'event_banner_sq' => 'required|image|mimes:jpeg,png|dimensions:width=720,height=300'


Controller
public function update( EventFormRequest $request , $id)
    {
        $event = Event::with('capacity')->where('event_id',$id)->first();

        $categories = $request->get('event_category');
        $categories = implode(",",$categories);

        $tags = $request->get('event_tag');
        $tags = implode(",",$tags);

        $start_date = $request->get('start_date');
        $start_time = $request->get('start_time');

        $end_date = $request->get('end_date');
        $end_time = $request->get('end_time');
        
        //combine date & time
        $event_start = Carbon::parse($start_date.' '.$start_time);
        $event_end = Carbon::parse($end_date.' '.$end_time);

        $fileimage1 = $event->event_banner_sq;
        $fileimage2 = $event->event_banner_full;
        if($request->hasFile('event_banner_sq'))
        {
            Storage::disk('public')->delete($fileimage1);
            $pathImage1 = $request->file('event_banner_sq')->store('banners','public');
            $event->event_banner_sq = $pathImage1;
        }
        if($request->hasFile('event_banner_full'))
        {
            Storage::disk('public')->delete($fileimage2);
            $pathImage2 = $request->file('event_banner_full')->store('banners','public');
            $event->event_banner_full = $pathImage2;
        }

view

 <div class="col-md-6">
                        <img src="{{ Storage::url($event->event_banner_sq) }}" name="event_banner_sq" style="width:80%">
                        <button class="btn btn-warning" onclick="changeMethod1() ; return false ;" >Change Banner 1 </button>
                    </div>
<script>
    function changeMethod1(){
        $("#currentBanner1").hide();
        $("#changeBannerImage1").append('<div class="form-group"></div><label class="col-md-3 control-label" >Event Banner 1</label><div class="col-md-6"><input type="file" name="event_banner_sq" class="form-control"><span class="help-block"> Size of image must be 720x300</span></div></div></div>');
    }
</script>

FareedR started a new conversation API Without Passport

Is there any tutorial that show how to make an API without using passport ?