tanmay_das

Experience

14,270

3 Best Reply Awards

  • Member Since 11 Months Ago
  • 99 Lessons Completed
  • 1 Favorite

16th February, 2018

tanmay_das left a reply on Confusions About Laravel Storage Directory And Its Symlink • 1 week ago

Anything that's visible in the browser, shouldn't it be considered public? And if that's the case, shouldn't logo, banner etc. be considered public too?

tanmay_das left a reply on Confusions About Laravel Storage Directory And Its Symlink • 1 week ago

@mhankins It's not working. Maybe because it's pointing to /media/tanmay/3806FF1D11D87FF6/code/myapp/storage/app/private/logo.png, which translates into this:

http://localhost:3000/media/tanmay/3806FF1D11D87FF6/code/myapp/storage/app/private/logo.png

instead of being translated into this:

http://localhost:3000/storage/app/private/logo.png

...relative to my application, not my entire disk (media/tanmay/blah/....).

And I just realized it will never get past the storage/app directory, since the symlink in the public (http://localhost:3000/) directory is always pointing to storage/app/public/

The only solution I can see is to put my private assets in public directory :(

tanmay_das started a new conversation Confusions About Laravel Storage Directory And Its Symlink • 1 week ago

Okay, this is what I understand about the laravel storage so far:

All my public assets, things like profile pictures or any user-generated files should reside in myapp/storage/app/public and things that are not user-generated, but application-specific, such as: logo, banner etc., should reside outside the public directory. For instance, myapp/storage/app/private.

We create a symlink within the myapp/public/ directory that points to myapp/storage/app/public/ and we access our public assets by asset('storage/avatar.png'). It loads the avatar from storage/app/public/avatar.png

But how do I access my private assets? Say I want to load my logo.png file which is in storage/app/private/logo.png this path?

20th January, 2018

tanmay_das left a reply on Image Validation Rules Example • 1 month ago

Are you sure you didn't add it to a different form? Because 3 days ago, I had exactly the same issue and it was caused by the misplacement of the enctype attribute: https://laracasts.com/discuss/channels/laravel/laravel-multi-file-validation-fails

tanmay_das left a reply on Image Validation Rules Example • 1 month ago

In your opening <form> tag, add enctype="multipart/form-data" attribute.

19th January, 2018

tanmay_das left a reply on Route Exists But Page Not Found • 1 month ago

Is it because ->firstOrFail()?

tanmay_das started a new conversation Route Exists But Page Not Found • 1 month ago

I have a route:

Route::get('generateresult', '[email protected]');

[email protected]:

public function gen(){
        $examinees = \App\Examinee::all();
        foreach ($examinees as $examinee) {
            $result = new Result();
            $result->name = $examinee->user->name;
            $result->email = $examinee->user->email;
            $result->institution = $examinee->institution;
            $result->answered = count($examinee->user->submittedAnswers()->get());
            $result->correct = $examinee->user->get_correct_answers($examinee->user->id);
            $result->submitted_at = $examinee->user->submittedAnswers()->firstOrFail()->created_at;
            $result->save();
        }
    }

When i hit generateresult route, I get a page not found error. But if I return a string from gen() method, the string is displayed properly. What went wrong?

tanmay_das started a new conversation How To Add UTC +6:30 To A Carbon Instance • 1 month ago

I have a couple of row in a table with created_at timestamp. I want to show the value of created_at field in my view:

{{ $model->created_at }}

But this displays the default timezone it used during save(). How can I now adjust that timezone just to 'display' as if it was recorded with utc +6:30?

17th January, 2018

tanmay_das left a reply on How To Determine From And To In A Messaging Application • 1 month ago

@mstnorris Thanks for the tip, but setting or retrieving is not what I needed. I am looking for a way to "distinguish" sender from recipient and vice versa. What would be a common approach to determine to whom I am sending the message?

Currently this is what I am doing:

1. I set up a `Route::post` like this `/message/{to}` 2. A user opens a message thread (within which, he can also reply). I set the `from` to whoever the currently logged in user is, by calling `auth()->id()` 3. I fetch the row of the last message. If the id of currently logged in user is found in either of `to` or `from` field, I set the value of the opposite column as recipient (`to`).

Is this a good approach?

tanmay_das left a reply on Laravel Multi File Validation Fails • 1 month ago

@morteza Yeah I added enctype attr to the wrong form. My mistake :)

16th January, 2018

tanmay_das started a new conversation Laravel Multi File Validation Fails • 1 month ago

I have a multiple file input field:

<input type="file" id="documents" name="documents[]" multiple>

In ProjecRequest:

    $rules = [
      'documents.*' => 'mimes:doc,pdf,jpeg,bmp,png|max:20000',
    ];
    return $rules;

In [email protected]:

    public function store(ProjectRequest $request)
    {
       $project = Project::create([
         /*key=>value removed to keep the question clean*/
       ]);

       foreach ($request->documents as $document) {
           $filename = $document->store('documents');
           Document::create([
              'project_id' => $project->id,
              'filepath' => $filename
           ]);
       }
       return redirect()->back();
    }

But when I try to upload a png or pdf I get the following validation error:

The documents.0 must be a file of type: doc, pdf, jpeg, bmp, png.

14th January, 2018

tanmay_das started a new conversation How To Determine From And To In A Messaging Application • 1 month ago

My message table looks like this:

message(id, from, to, body, is_seen).

Here, both from and to are the ids of the user table. I can always determine the from id by calling auth()->id() but how do I fill up the to column?

10th January, 2018

tanmay_das left a reply on Whoops! Class App\Http\Controllers\Type Does Not Exist • 1 month ago

It looks like your editor is trying to be ultra-smart and putting the Type $var = null placeholder in each of the methods.

Change this:

class PagesController extends Controller
{
    public function getIndex(Type $var = null)
    {
        return view('pages.welcome');
    }

    public function getAbout(Type $var = null)
    {
        return view('pages.about');
    }

    public function getContact(Type $var = null)
    {
        return view('pages.contact');
    }

}

To this:

class PagesController extends Controller
{
    public function getIndex()
    {
        return view('pages.welcome');
    }

    public function getAbout()
    {
        return view('pages.about');
    }

    public function getContact()
    {
        return view('pages.contact');
    }

}

8th January, 2018

tanmay_das started a new conversation Laravel Shared Hosting Deployment • 1 month ago

I have a copy of my project in my office pc and I pushed the project to a bitbucket git repo. I have been instructed to deploy the project as soon as I go home. I came to home and:

  1. Cloned the repo to home pc. It didn't have the vendor directory as it is ignored by the gitignore file

  2. A quick google search suggested me to run composer install, but it didn't work because of unmet requirements

  3. So I ran composer update instead and it regenerated the vendor directory. Meanwhile, I already uploaded everything else except the vendor directory

  4. gitignore also ignores the .env file, so I duplicated .env.example and renamed it to .env and generated a key using php artisan key:generate and uploaded the file to the server

  5. I am currently at this stage, about to upload the vendor directory. It contains a lot of files and will consume a huge amount of time. If anyone could confirm that all the above steps were ok and I did not ruin anything I would upload the vendor directory

6th January, 2018

tanmay_das left a reply on Blade Nested Section Produces Misformatted DOM • 1 month ago

@calder12 Thanks but don't you think this is anti-DRY? I mean for every single page, I would have to create a different sidebar x_sidebar, y_sidebar, z_sidebar and so on...

tanmay_das left a reply on Can Anyone Please Tell Me The Font Name • 1 month ago

In headings, they are using Roboto. In paragraphs, Open Sans Light.

tanmay_das started a new conversation Blade Nested Section Produces Misformatted DOM • 1 month ago

Here is the content of my home.blade.php file:

@extends('layouts.master')
@section('content')
  @extends('partials.sidebar')
    @section('pagecontent')
      This is home
    @endsection
@endsection

layouts/master.blade.php contains the main layout which has the typical <html><head><body> structure. In it's <body>, I am yielding to a section called content:

<!DOCTYPE html> 
<html>
<body>
  <div id="app">
    @yield('content')
  </div>
</body>
</html>

and in my parials/sidebar.blade.php, I am yielding to a section called pagecontent:

<div id="page-content-wrapper">
        <div class="container-fluid">
            @yield('pagecontent')
        </div>
</div>

So I would naturally expect a DOM like this:

<!DOCTYPE html> 
<html>
<body>
  <div id="app"> <!-- @section('content') -->
    <div id="page-content-wrapper">
        <div class="container-fluid">
            This is home <!-- @section('pagecontent') -->
        </div>
   </div>
  </div>
</body>
</html>

Unfortunately, that's not the DOM my blade views are rendering. My sidebar partial doesn't get injected inside the master layout, instead, it is appended to the DOM as a sibling of the Entire Document:

<div id="page-content-wrapper">
   <div class="container-fluid">
       This is home <!-- @section('pagecontent') -->
   </div>
</div>

<!DOCTYPE html> 
<html>
<body>
  <div id="app"> <!-- @section('content') -->
  </div>
</body>
</html>

How can I fix this?

24th December, 2017

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

Thanks @Snapey , thanks a lot :)

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

I am not manually creating the link, the link gets generated by (ResetPassword)[https://laravel.com/api/5.4/Illuminate/Auth/Notifications/ResetPassword.html] Notification:

    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->line('You are receiving this email because we received a password reset request for your account.')
            ->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false)))
            ->line('If you did not request a password reset, no further action is required.');
    }

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

But why is laravel generating the link with a query string? It doesn't happen with the make:auth. I just tested. With make:auth, it's generated as reset/$token and not as reset?$token

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

Interestingly, when I change my reset link from this:

http://localhost:8000/password/reset?8331031f0abcf4686ec143483fff403d5d9adbc893c6d20292ffb99c913e9e01

to this:

http://localhost:8000/password/reset/8331031f0abcf4686ec143483fff403d5d9adbc893c6d20292ffb99c913e9e01

Then the reset view loads! What should I do?

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

I believe the source of the problem is in this route:

Route::get('/password/reset/{token}', '[email protected]')->name('password.request');

Somehow it's failing to receive the $token, hence the redirection. As mentioned in the ResetsPasswords trait:

/**
     * Display the password reset view for the given token.
     *
     * If no token is present, display the link request form.
     *

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

Something went wrong. I can send the reset email. But for some reason when I click on the reset password link, I get redirected back to showLinkRequestForm() method. Here is what I have done so far:

My routes:

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

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

Route::get('/password/reset/{token}', '[email protected]')->name('password.request');

Route::post('/password/reset', '[email protected]')->name('password.reset');

ForgotPasswordController.php:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class ForgotPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset emails and
    | includes a trait which assists in sending these notifications from
    | your application to your users. Feel free to explore this trait.
    |
    */

    use SendsPasswordResetEmails;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    public function showLinkRequestForm()
    {
        return view('password.email');
    }
}

ResetPasswordController.php:

<?php

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;

class ResetPasswordController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Password Reset Controller
    |--------------------------------------------------------------------------
    |
    | This controller is responsible for handling password reset requests
    | and uses a simple trait to include this behavior. You're free to
    | explore this trait and override any methods you wish to tweak.
    |
    */

    use ResetsPasswords;

    /**
     * Where to redirect users after resetting their password.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    public function showResetForm(Request $request, $token = null)
    {
        return view('password.reset')->with(
            ['token' => $token, 'email' => $request->email]
        );
    }
}

password.email view (this one loads perfectly):

@extends('layouts.master')
@section('content')
    <div class="col-sm-8 offset-sm-2">
        <h1>Forgot Password</h1>
        <form method="POST" action="/password/email">
            {{ csrf_field() }}
            <div class="form-group">
            <label for="email">E-mail</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Enter email">
          </div>
          <button type="submit" class="btn btn-primary">Send Password Reset Link</button>
        </form>
    </div>
@endsection

password.reset view (this one does not):

@extends('layouts.master')

@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="panel panel-default">
                <div class="panel-heading">Reset Password</div>

                <div class="panel-body">
                    <form class="form-horizontal" method="POST" action="{{ route('password.request') }}">
                        {{ csrf_field() }}

                        <input type="hidden" name="token" value="{{ $token }}">

                        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                            <label for="email" class="col-md-4 control-label">E-Mail Address</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control" name="email" value="{{ $email or old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
                            <label for="password" class="col-md-4 control-label">Password</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
                            <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>

                                @if ($errors->has('password_confirmation'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('password_confirmation') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-primary">
                                    Reset Password
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

@Snapey There are two controllers for password reset: 1. ForgotPasswordController 2. ResetPasswordController.

If I copy these two controllers in my current project and add necessary routes like below, is it going to take care of the entire resetting process:

‍‍‍‍‍``` Route::get('password/reset', '[email protected]'); Route::post('password/email', '[email protected]'); Route::get('password/reset/{token}', '[email protected]'); Route::post('password/reset', '[email protected]');


The `ForgotPasswordController` uses the `SendPasswordResetEmails` trait, in which, the `showLinkRequestForm()` method returns a view that Laravel auto-generates during make:auth process. Can I override that method to return my own view?

And the `ResetPasswordController` uses the `ResetPasswords` trait where the `showResetForm()` also returns laravel generated view. I will have to override it too.

Am I on the right track?

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

@Snapey Thanks, I guess I am beginning to understand the logic behind it.

I have a question though. How do I access the password_reset table that comes with laravel? I mean there is no model associated with it...

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

@rumm.an Okay, let's say I've sent the mail with the url: mycoolsite.com/passwordreset/token/.$token

Then what? How can I track which user clicked the reset link, otherwise how would I know who is trying to reset the password?

tanmay_das left a reply on Problem With Find Out Category Name | Laravel 55 • 2 months ago

Yes, you can. But let me explain a few things first: When you execute

$categories = Category::where('id', $post->category_id)->orderBy('category_name')->get();

you always get a collection of one result, because your where clause will never return more than one row, since there is one row associated with one unique id. You can think of what you are doing now as using a bucket for only one fish.

If you expect only one fish (row) using a bucket (collection) is overkill. Instead what you could do is use your hand (methods like: first() and find()):

You can achieve this in one of the two ways:

$category = Category::where('id', $post->category_id)->get()->first();

Or:

$category = Category::find($post->category_id);

Then you can throw your fish in blade like this: {{ $category->category_name }}

tanmay_das left a reply on Problem With Find Out Category Name | Laravel 55 • 2 months ago

@NoneNameDeveloper Take a look at your variable name. It's in plural: $categories. So you are fetching a 'collection' of categories, not 'objects'.

You will have to iterate over the $categories collection like this:

@foreach($categories as $category)
    {{ $category->category_name }}
@endforeach

tanmay_das left a reply on Implementing Reset Password Feature Without Make:auth • 2 months ago

@N3xus But how can I generate the unique reset password link?

tanmay_das left a reply on Problem With Find Out Category Name | Laravel 55 • 2 months ago

It's either categories_name or category_name. Assuming your column name is category_name and not categories_name, you should change this:

{{$categories ->categories _name}}

to this:

{{ $categories ->category _name }}

tanmay_das started a new conversation Implementing Reset Password Feature Without Make:auth • 2 months ago

I am following this series and I have set up the registration and login feature from the scratch, without using make:auth, as shown in episode 18 and episode 19 .

The make:auth command generates controllers and views for password reset, but how do I implement it now from the scratch? At this point I don't have any controller or view setup for resetting password.

8th December, 2017

tanmay_das left a reply on IDE For Laravel • 2 months ago

On sublime, install [Laravel Blade Highlighter] (https://packagecontrol.io/packages/Laravel%20Blade%20Highlighter)

On PhpStorm you can customize it yourself from Settings->Editor->Color Scheme->Blade

28th October, 2017

tanmay_das started a new conversation Displaying Recursive Model Data With Vuejs In Laravel • 3 months ago

I have 3 models: Lesson, Quiz and Answer. Lesson hasMany() Quizzes, Quiz hasMany() Answers. To view the quiz and each answer associated with the quiz, in my blade template I was doing something like this:

@foreach ($lesson->quizzes as $quiz)
    <p>{{ $quiz->title }}</p>
    @foreach ($quiz->answers as $answer)
    <div class="field">
        <control>
            <inp type="radio" @optionselected="onRadioChanged" name="{{ 'answer'.$answer->quiz_id }}" val="{{ $answer->id }}">{{ $answer->title }}</inp>
        </control>
    </div>
    @endforeach
    <hr>
@endforeach

It works fine. But the problem is it populates the modal with all of the quizzes, like this: https://imgur.com/jmOL1vl

But I want only one quiz at a time and I would like to show the next quiz when the user clicks the Next button. And to do that, I guess I need the help of Vue. So I ended up doing something like this:

@foreach ($lesson->quizzes as $quiz)
    <p>{{ $quiz->title }}</p>
    <div class="field" v-for="answer in answers">
        <control>
            <inp type="radio" @optionselected="onRadioChanged" name="answer.quiz_id" val="answer.id">@{{ answer.title }}</inp>
        </control>
    </div>
    <hr>
@endforeach 

I am passing $lesson->quizzes as the argument of the vue method onShowViewQuizModal(quizzes) to fetch the answers forEach() of the quizzes with an ajax call:

data: { answers: [] },
methods:{
    onShowViewQuizModal: function(quizzes){
          var that = this;
        quizzes.forEach(function(quiz){
          axios.post('/fetchanswers', {quizid: quiz.id}).then(function(response){
            that.answers = response.data;
            console.log(that.answers);
          });

        });

        this.showViewQuizModal = true;
      } 
}

And the route method which is responding to this ajax call:

Route::post('/fetchanswers',function(){
    $quiz = Quiz::find(request('quizid'));
    return $quiz->answers;
});

But now, In my view, my modal is being populated with the last answer only: https://imgur.com/MmHGe2Q How can I fix this?

tanmay_das started a new conversation Sending Nested Data From Blade To Vue • 3 months ago

I have 3 models in a laravel application: 1) Lesson 2) Quiz 3) Answer (I should have named it Option actually). Their relationship is set up in this manner: Each Lesson has Quizzes, each Quiz has Answers. In a blade file I have access to a $lesson instance. I want to send both $lesson->quizzes and $quiz->answers from Blade to a VueJS method. Now I can only send the quizzes:

    <modal-button color="success" size="small" icon="eye" header="View Quiz" btntxt="View Quiz" @showmodal="onShowViewQuizModal({{ $lesson->quizzes }})">
    @include('partials.quizform')
    </modal-button>

I capture the sent quizzes in my vuejs method and assign the array of objects to a vuejs data property:

    onShowViewQuizModal(quizzes){
        this.quizzes = quizzes;
    }

Within the quizform partial, I am trying to display these nested sets of data. I have something like this in my mind:

    <div v-for="quiz in quizzes">
        <p>@{{ quiz.title }}</p>
        
        <div v-for="answer in quiz.answers">
            <p>@{{ answer.title }}</p>
        </div>
    </div>

Only the outer v-for will work, but the inner v-for won't because quiz.answers is probably undefined.

I hope you get the idea and I'm sure people must've come across this situation at some point. How can I handle the situation?

20th September, 2017

tanmay_das left a reply on How Can I Return A Single Data Value For Each Input • 5 months ago

Shouldn't the updateCart() method be inside the methods:{} property?

18th September, 2017

tanmay_das started a new conversation Generating Action Url In A Form Relative To The Root Url • 5 months ago

I have a resourceful route,

Route::resource('posts','PostController');

I am creating a Post from this route: http://localhost:3000/posts/create, where I have a form:

<form action="{{ route('posts.store', false) }}" method="POST">
        @include('dashboard.partials.postsform')
</form>

This submits the form to this URL: http://localhost:3000/posts/posts But I want this to be submitted to be this URL: http://localhost:3000/posts

I could hard-code it in the action attribute like http://localhost:3000/posts but what if my application has a different base URL than localhost?

17th September, 2017

tanmay_das started a new conversation Suggest Me Some Tools/strategies For Brainstorming The Application Before Jumping Into The Code • 5 months ago

Up to this point I have been making small/medium size applications. I'd do all the brainstorming in my head and I'd make my design decisions in the middle of the development. But as I am moving towards larger applications I can't do this in my head anymore. I need to have my entire project plan laid out right in front of my eyes. If you are a one-man team, I am sure at some point of your career many of you have faced the similar situation. How do you handle the 'pre-production' phase of your project? What steps do you follow? What tools do you use for visualization? I need some suggestions...

10th September, 2017

tanmay_das left a reply on Foreign Key Constraints On Polymorphic Relationship • 5 months ago

Okay, after googling a bit, I realized why it is not possible to apply foreign key on polymorphic relations. I came across this laracasts discussion

https://www.laracasts.com/discuss/channels/eloquent/polymorphic-relations-on-delete/replies/353658

and decided to be explicit on the controller's destroy() method. Any alternative solution will be greatly appreciated.

tanmay_das started a new conversation Foreign Key Constraints On Polymorphic Relationship • 5 months ago

https://laravel.com/docs/5.5/eloquent-relationships#polymorphic-relations

In this official example of polymorphic relations, the following table structure has been used:

posts
    id - integer
    title - string
    body - text

videos
    id - integer
    title - string
    url - string

comments
    id - integer
    body - text
    commentable_id - integer
    commentable_type - string

How do I set commentable_id as a foreign key in such a way, so that when a post or a video is deleted, all comments associated with it will also be deleted?

The example shown here : https://laravel.com/docs/5.5/migrations#foreign-key-constraints

makes use of the on() method by passing a single table name, users. What if I wanted to apply this on two tables, posts and videos?

$table->foreign('user_id')
      ->references('id')->on('users')
      ->onDelete('cascade');

8th September, 2017

tanmay_das started a new conversation When To Use A Repository • 5 months ago

In many of the laracasts episodes I see Jeffrey use repositories, UserRepository, PostRepository etc. But the tasks that are performed there can also be performed on the Model itself. When should I use a Repository? Can someone please give me an example of a good use case of a Repository?

4th September, 2017

tanmay_das left a reply on V-for In Options Not Working... • 5 months ago

Any update to this thread?

tanmay_das left a reply on How To Use A Vue Property Within Blade Directives • 5 months ago

<script>
    window.num: {{$num}};
</script>

Where does this $num variable come from? If I had a $num variable, couldn't I use that within the for loop in the first place, like this:

@for ($i = 1; $i <= count($myModel->first()->myCustomMethod($num)); $i++)
                <option value="{{ $i }}">{{ $i }}</option>
@endfor 

num is a dynamic JS variable, its value changes according to the user input. So the statement window.num: {{$num}}; won't do the job here since this statement has to be re-evaluated for the new value of num

tanmay_das left a reply on How To Use A Vue Property Within Blade Directives • 5 months ago

Looks like an ajax call is required in this case

tanmay_das left a reply on How To Use A Vue Property Within Blade Directives • 5 months ago

@topvillas That won't work :P Because num is bound to an input as a v-model

tanmay_das left a reply on How To Use A Vue Property Within Blade Directives • 5 months ago

@topvillas Is there any non-AJAX solution for situations like this?

tanmay_das started a new conversation How To Use A Vue Property Within Blade Directives • 5 months ago

I have a vue prop say

{
    num: ''
}

Now I would like to use that property inside a blade for directive:

@for ($i = 1; $i <= count($myModel->first()->myCustomMethod(@{{ num }})); $i++)
                <option value="{{ $i }}">{{ $i }}</option>
@endfor 

But it throws Parse Error. How do I use the vue prop? Also num is a string, how can I convert it into integer before passing it as an argument to myCustomMethod()?

tanmay_das left a reply on Conditional Form Validation • 5 months ago

@bashy Thanks, I'll look into it :)

tanmay_das left a reply on Conditional Form Validation • 5 months ago

@bashy I get your point. But I am not showing both of the fields to the user.

And in @JackJones' defense, it's okay to return an error when neither of them are filled out. I mean given my set of required_without rules, isn't that a natural consequence? Remember, at least one of them has to be filled. So the validation passes when at least one or both of them are filled.

I can only confirm the case of only one being filled. Because there is no way for me (or any normal user) to pass both values from the form. When I select pages, the category selectbox disappears from the DOM and when I select categories the page selectbox disappears from the DOM. I know some people can be sneaky and create another select input from the DevTools and pass both of them but right now instead of learning how to extend the validator, I am putting my money on the least likelihood of people being deceitful.

3rd September, 2017

tanmay_das left a reply on Conditional Form Validation • 5 months ago

@JackJones It's working!

Here are my updated rules:

'title' => 'required|min:3',
'page_id' => 'required_without:category_id',
'category_id' => 'required_without:page_id'
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.