Ap3twe

Ap3twe

Member Since 5 Months Ago

Experience Points
8,280
Total
Experience

1,720 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
61
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
8,280 XP
20 Sep
22 hours ago

Ap3twe started a new conversation Display Array Of Files Depending On The Condition

I am trying to display an array of 3d files. How do I write a condition to display the files based on the extension? Something like if the request file extension ends in .jpg shows the first file in the array and if it ends in .png, show all the array of files.

blade view

 <div class="iframe-container"> 
       <canvas id="fullscreen" class="3dviewer" sourcefiles="{{asset('storage/uploads/stl/'. $project->labstlfiles) }}" width="960px" height="600px"></canvas>

   </div>

Controller

if ($request->hasFile('labstlfiles')){
foreach ($request->file('labstlfiles') as $file) {
            $labstlfileNameToStore =$file->getClientOriginalName();
            $path = public_path('storage/uploads/stl');
            $file->move($path, $labstlfileNameToStore);
        }
}

14 Aug
1 month ago

Ap3twe left a reply on Image Display Not Showing In Cpanel

Look at the path carefully. What is the tree of your application? Also, check the file extensions like jpeg or jpg.

Ap3twe left a reply on How To Generate Random(6) Numbers For Each Insert Into Database

@cronix Nothing much. just in case I am reading through the database, I just wanted to remember the number. But I guess will just remember the last digit is the only thing that is unique. Thank you once again

Ap3twe left a reply on How To Generate Random(6) Numbers For Each Insert Into Database

I have inserted the $sixDigitId value in my view. Working alright but was thinking if there is a way I can update the $table->string('case_number')->nullable(); with the value of $sixDigitId. I can leave it out if is not possible

            <thead>
                    <tr>
                       <th>Case Number</th>
                    </tr>
            </thead>
            <tr>
                    @php
                    $sixDigitId =  str_pad($project->id, 6, '1635', STR_PAD_LEFT);
                    @endphp

                 <td>{{$sixDigitId}} </td>
          </tr>

Ap3twe left a reply on How To Generate Random(6) Numbers For Each Insert Into Database

@cronix @tray2 Bonus/Bogus question, Is there a way I can update the column case_number with the $sixDigitId in the views? I guess is not possible cuz the DB updates before I generate it in the view.

Ap3twe left a reply on How To Generate Random(6) Numbers For Each Insert Into Database

@cronix It works Perfectly. Thank you again. I replaced the 0 with a sequential number like 1234

Ap3twe left a reply on How To Generate Random(6) Numbers For Each Insert Into Database

Thank you @tray2 once again 4 your help. I appreciate

Ap3twe started a new conversation How To Generate Random(6) Numbers For Each Insert Into Database

I want to insert random case numbers for each project. ex. 084748. I know you cant have 2 auto increment in MYSQL table. How do I go about it?

"The reason I need that is I will send it to a rest API that uses 6 numbers to identify each case"

This is my schema

Schema::create('projects', function (Blueprint $table) {
        $table->unsignedBigInteger('user_id');
        $table->bigIncrements('id');
        $table->string('case_number')->default('084748');
        $table->timestamps();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
}
13 Aug
1 month ago

Ap3twe left a reply on Sending Mail To Project Owner

In other words, we could have used user as the function name by removing the user_id am I right?

Ap3twe left a reply on Sending Mail To Project Owner

Thank you it works. But can you explain to me how in the second argument 'User_id' the model automatically knows the relationship?

Ap3twe started a new conversation Sending Mail To Project Owner

Admin updates a project that belongs to a user then I want to trigger mail notification to the user and also me. $request-user() is for the admin. How do I pass the email of the project owner? I have tried some methods but I can't get it right.

Example 1. I get "Trying to get property 'email' of non-object "

          $owner =  $project->user_id->email;
          Mail::to([$request->user(), $owner])->send(new ProjectUpdated($project));

Example 2.

          $owner =  Project::where('user_id', auth()->id())->findOrFail('email');
         Mail::to([$request->user(), $owner])->send(new ProjectUpdated($project));
12 Aug
1 month ago

Ap3twe left a reply on Does Laravel Session Has A Unique Key?

An example of finding a session of the created_id. This looks for the key created_id

        $project = Project::where('user_id', auth()->id())->find(session('created_id'));

        return view 

    }```

raw php 
```<?php
function session(
    $key = null,
    $default = null
) { }```

Ap3twe left a reply on How To Pass Contoller Wild Card Into Mail Template?

Thank you. Working perfectly.

09 Aug
1 month ago

Ap3twe started a new conversation How To Pass Contoller Wild Card Into Mail Template?

I want to pass a Project variable like {{project->case_number}} into the mail template. Here is my template

@component('mail::message')
Case: number

Your case has been created successfully for patient
Your case number is 1608507.

@component('mail::button', ['url' => url('/bronk/cases')])
View Project
@endcomponent

Thanks,<br>
{{ config('app.name') }}
@endcomponent ```

How do I go about it? I tried @extends('layout') but nothing worked
12 Jul
2 months ago

Ap3twe left a reply on Multiple Inputs Field Styling

I will create jsfiddle file and show it so you can get it

24 Jun
2 months ago

Ap3twe started a new conversation FIrst Laravel Project Completed

Thanks to all the team and helpful guys on this platform. I completed my first laravel project. Special thanks to regulars like @Cronix, Tray2, Jlrdw, Snapey, and Bobbybouwmann. I will keep learning that is the keyword!

23 Jun
2 months ago

Ap3twe left a reply on Multiple Inputs Field Styling

@TRAY2 - Let me clarify. Css input fields is tricky to to style. I found this code with styling and drag and drop. It works perfectly. I just want to use it many times in the page. In the current state when I upload a file, the script affects all the other input fields. I can solve it by using classes for each input field and having multiple Js script dedicated to each. What I want is how do is: I wanna use only 1 Js script to control each input field independently? Thank you I hope you get it now. Example : input 1, input 2, input 3. They are not related but use one script to manipulate the styling of each independently.

21 Jun
2 months ago

Ap3twe left a reply on Multiple Inputs Field Styling

I was thinking of a better way of not using the script many times. That means I have to copy the script 9ine times

Ap3twe left a reply on Multiple Inputs Field Styling

@TRAY2 - I am styling file input fields.

Ap3twe started a new conversation Multiple Inputs Field Styling

I would like to use this input file code in my project. My reason is styling the input field. The downside is I have 9 input fields in my HTML. The reason I did not use one input [multiple] is that they are not related so I want the user to upload the files each one by one depending on the condition I will set. I found this code. When I upload a file It gets loaded to all the rest of the inputs. Is there a way I don't have to duplicate the many times? I want to use only one script to control all the input fields. the question is it is possible or I have to copy each script separately?

<div class="file-upload">
  <button class="file-upload-btn" type="button" onclick="$('.file-upload-input').trigger( 'click' )">Add Image</button>

  <div class="image-upload-wrap">
    <input class="file-upload-input" type='file' onchange="readURL(this);" accept="image/*" />
    <div class="drag-text">
      <h3>Drag and drop a file or select add Image</h3>
    </div>
  </div>
  <div class="file-upload-content">
    <img class="file-upload-image" src="#" alt="your image" />
    <div class="image-title-wrap">
      <button type="button" onclick="removeUpload()" class="remove-image">Remove <span class="image-title">Uploaded Image</span></button>
    </div>
  </div>
</div>


  .file-upload {
    background-color: #ffffff;
    width: 300px;
    min-width: 15%;
    margin: 0 auto;
    padding: 20px;
  }

  .file-upload-btn {
    width: 100%;
    margin: 0;
    color: #fff;
    background: #085aad;
    border: none;
    padding: 10px;
    border-radius: 4px;
    border-bottom: 4px solid #085aad;
    transition: all .2s ease;
    outline: none;
    text-transform: uppercase;
    font-weight: 700;
  }

  .file-upload-btn:hover {
    background: #F4754E;
    color: #ffffff;
    transition: all .2s ease;
    cursor: pointer;
  }

  .file-upload-btn:active {
    border: 0;
    transition: all .2s ease;
  }

  .file-upload-content {
    display: none;
    text-align: center;
  }

  .file-upload-input {
    position: absolute;
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    outline: none;
    opacity: 0;
    cursor: pointer;
  }

  .image-upload-wrap {
    margin-top: 20px;
    border: 4px dashed #085aad;
    position: relative;
  }

  .image-dropping,
  .image-upload-wrap:hover {
    background-color: #999;
    border: 4px dashed #ffffff;
  }

  .image-title-wrap {
    padding: 0 15px 15px 15px;
    color: #222;
  }

  .drag-text {
    text-align: center;
  }

  .drag-text h3 {
    font-weight: 100;
    text-transform: uppercase;
    color: #085aad;
    padding: 60px 0;
  }

  .drag-text h3:hover {
     color: #fff;
  }

  .file-upload-image {
    max-height: 200px;
    max-width: 200px;
    margin: auto;
    padding: 20px;
  }

  .remove-image {
    width: 200px;
    margin: 0;
    color: #fff;
    background: #F4754E;
    border: none;
    padding: 10px;
    border-radius: 4px;
    border-bottom: 4px solid #b02818;
    transition: all .2s ease;
    outline: none;
    text-transform: uppercase;
    font-weight: 700;
  }

  .remove-image:hover {
    background: #c13b2a;
    color: #ffffff;
    transition: all .2s ease;
    cursor: pointer;
  }

  .remove-image:active {
    border: 0;
    transition: all .2s ease;
  }
function readURL(input) {
    if (input.files && input.files[0]) {

      var reader = new FileReader();

      reader.onload = function(e) {
        $('.image-upload-wrap').hide();

        $('.file-upload-image').attr('src', e.target.result);
        $('.file-upload-content').show();

        $('.image-title').html(input.files[0].name);
      };

      reader.readAsDataURL(input.files[0]);

    } else {
      removeUpload();
    }
  }

  function removeUpload() {
    $('.file-upload-input').replaceWith($('.file-upload-input').clone());
    $('.file-upload-content').hide();
    $('.image-upload-wrap').show();
  }
  $('.image-upload-wrap').bind('dragover', function () {
          $('.image-upload-wrap').addClass('image-dropping');
      });
      $('.image-upload-wrap').bind('dragleave', function () {
          $('.image-upload-wrap').removeClass('image-dropping');
  });
22 May
3 months ago

Ap3twe left a reply on How Do I Get The Updated_at

Any suggestion on @cronix method?

21 May
3 months ago

Ap3twe left a reply on How Do I Get The Updated_at

@TRAY2 - Your method works perfectly. The only thing is I get the default value NEW in the DB.

Ap3twe left a reply on How Do I Get The Updated_at

@CRONIX - I got an empty value in the DB. This is how I tried it

$published = $project->publish = "Published";

$project->fill(['publish' => $published]);

I get the value "published" when I dump it.

Ap3twe left a reply on Getting The Value Of Date (Y:M:D)?

@CRONIX - Thank you. It works

Ap3twe left a reply on How Do I Get The Updated_at

@TISUCHI - Let me clarify my question. In my project, A user creates a project and I show the value from the database "New". I passed a default value '' New'' to the db. I wanna get the second value from the boolean if the user updates the project. That value is ''Published''.

Ap3twe left a reply on Getting The Value Of Date (Y:M:D)?

@TISUCHI - I wasn't sure. Did you put it in the User model or controller?

Ap3twe left a reply on How Do I Get The Updated_at

@TISUCHI - I tried this condition. I think the updated_at updates when I create a project.

@if ($project->updated_at)
       <td> <a href="/smiledesign/{{$project->id}}/userproject">Published</a></td>
        @else
       <td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->publish}}</a></td>
        @endif

Ap3twe left a reply on Getting The Value Of Date (Y:M:D)?

@tisuchi Did not work. A question though is the getFromDateAttribute a global method from laravel? I copied that function on stackoverflow.

Ap3twe started a new conversation How Do I Get The Updated_at

I want to get the value of the boolean when a project is updated. The problem is in MySQL database, the updated_at gets updated when a project is created. How do I get the value published when a project is updated?

This is the table schema

$table->enum('publish', ['New', 'Published'])->nullable()->default('New');

In the view, I get the default value

<td> <a href="/smiledesign/{{$project->id}}/userproject">{{$project->publish}}</a></td>

I wanna get the boolean Published when the project gets updated

Ap3twe started a new conversation Getting The Value Of Date (Y:M:D)?

I wanna get only Y:M:D. In laravel the created_at returns Y,M,D, hour, minutes and second. I tried to use public function getFromDateAttribute($value) { return \Carbon\Carbon::parse($value)->format('d-m-Y'); } in the user model. It still returns 2019-05-15 20:38:42

17 May
4 months ago

Ap3twe left a reply on Laracast Possibility Of Adding Friends & Messaging Directly

@JLRDW - I get you. What about in case we wanna hire or collaborate with someone. How can we shoot the person a message?

16 May
4 months ago

Ap3twe started a new conversation Laracast Possibility Of Adding Friends & Messaging Directly

It will be useful if we can add users as friends on laracast. What do yall think?

Ap3twe left a reply on Making A Route Public For Anyone To View

I fixed it.. I will test it for days and confirm it guys.abort_unless(auth()->user()->isAdmin || $project->user_id == auth()->id(), 403); Thank you all. I appriciate your help

Ap3twe left a reply on Making A Route Public For Anyone To View

How do I give access to the admin too? How do I write the condition by adding isAdmin? auth()->user()->isAdmin

Ap3twe left a reply on Making A Route Public For Anyone To View

@SNAPEY - Sorry it is working when I changed abort_if(! $project->user_id == auth()->id(), 403); to abort_if( $project->user_id !== auth()->id(), 403);

Ap3twe left a reply on Making A Route Public For Anyone To View

@SNAPEY - I tried your solution. The route does not abort. I dump it and it returns null

$bbd  =  abort_if(! $project->user_id == auth()->id(), 403);
        dd($bbd);

Ap3twe left a reply on Making A Route Public For Anyone To View

@CRONIX - I posted all the controllers

Ap3twe left a reply on Making A Route Public For Anyone To View

This is my middleware

<?php

namespace App\Http\Middleware;
use App\Project;

use Closure;

class FinalForm
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */


    public function handle($request, Closure $next)
    {

        // $project = Project::where('user_id', auth()->id())->get();
        $project = Project::find('id');
        $user_id = $project->user_id;
        if($user_id != auth()->user()->id){
            return redirect('/')->with('error', 'You are not able to see this page');

        }


        return $next($request);
    }
}

Controller

    // Published page
    public function published(project $project){
        $project = Project::where('user_id', auth()->id())->find(session('created_id'));
        return view ('/smiledesign.published', compact('project'));

    }

    public function doctorfinalform(Project $project, request $request){

        // $this->authorize('doctorfinalform', $project);

        return view('smiledesign.doctorfinalform', compact('project'));
    }

Route

Route::get('/smiledesign/{project}/doctorfinalform', '[email protected]')->middleware('finalForm');

Ap3twe left a reply on Making A Route Public For Anyone To View

@CRONIX - I want it to be dynamic. Assigning 4 is hard coded. I want to block other users from seeing the form.

Ap3twe left a reply on Making A Route Public For Anyone To View

@JLRDW - I appreciate. I am learning

Ap3twe left a reply on Making A Route Public For Anyone To View

@CRONIX - Replacing the string with integer throws an error Use of undefined constant id - assumed 'id' (this will throw an Error in a future version of PHP)

Ap3twe left a reply on Making A Route Public For Anyone To View

I get error Trying to get property 'user_id' of non-object

    public function handle($request, Closure $next)
    {
 
        $project = Project::find('id');
        $user_id = $project->user_id;
        if($user_id != auth()->user()->id){
            return redirect('/')->with('error', 'You are not able to see this page');
 
        }
 
 
        return $next($request);
    }
}

Ap3twe left a reply on Making A Route Public For Anyone To View

@SNAPEY - All doctors are protected. The problem I have is I am taking the form submitted by the doctor and updating it with new contents and sending it back to him. That makes it that the route is coming from protected admin and then releasing access back to the doctor. If I release access as public routes, anybody can see each other project. I am gonna protect it with the suggestion from @jlrdw

15 May
4 months ago

Ap3twe left a reply on Making A Route Public For Anyone To View

@JLRDW - I created a middleware. Yet all users can see each other project. What condition do I have to provide?

Route::get('/smiledesign/{project}/doctorfinalform', '[email protected]')->middleware('finalForm');

<?php

namespace App\Http\Middleware;

use Closure;

class FinalForm
{
    
    public function handle($request, Closure $next)
    {

        if(auth()->user()->id){
           
        }
        return $next($request);
    }
}

Ap3twe left a reply on Making A Route Public For Anyone To View

@SNAPEY - @snapey That is what I was thinking. I have to make a decision to leave that out. Security is important. I will limit it to the doctor

Ap3twe left a reply on Making A Route Public For Anyone To View

@I need the authentication in the ```__contruct()`` or else all the pages will be public. I want only the doctorfinalform to be public

Ap3twe started a new conversation Making A Route Public For Anyone To View

I want to allow a route to be public for anyone who has the URL to view. It is coming from protected routes from the admin. The admin creates the pages and the final page we would send it to a doctor who will also send it to the patients. How can I create a public URL from Route::get('/smiledesign/{project}/doctorfinalform', '[email protected]');

The view is like this http://blog.test/smiledesign/4/doctorfinalform

Here are my routes

  Auth::routes();

// Users Routes
Route::get('/home', '[email protected]')->name('home');
Route::get('/smiledesign/create', '[email protected]');
Route::post('/store', '[email protected]');
Route::get('/smiledesign/{project}/show', '[email protected]');
Route::get('/smiledesign/success', '[email protected]');
Route::get('/smiledesign/cases', '[email protected]');

// Doctor final form
Route::get('/smiledesign/{project}/doctorfinalform', '[email protected]');

// Admin redirect to dashboard
Route::get('/admin', '[email protected]')->middleware('admin');

// Admin Routes
Route::middleware('forStaff')->group(function () {
Route::get('/smiledesign/adminforms', '[email protected]');
Route::get('/smiledesign/{project}/records', '[email protected]');
Route::patch('/smiledesign/{project}', '[email protected]');
Route::get('/smiledesign/{project}/edit', '[email protected]');
Route::delete('/smiledesign/{project}', '[email protected]');
Route::get('/smiledesign/{project}/userproject', '[email protected]');
Route::get('/smiledesign/published', '[email protected]');
});

 // Published page
    public function published(project $project){
        $project = Project::where('user_id', auth()->id())->find(session('created_id'));
        return view ('/smiledesign.published', compact('project'));

    }

    public function doctorfinalform(Project $project, request $request){

        return view('smiledesign.doctorfinalform', compact('project'));
    }