aripal

at Fullstack developer

Experience

4,700

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 45 Lessons Completed
  • 0 Favorites

13th January, 2018

aripal left a reply on Increment Value When A Button Is Triggered • 4 days ago

@Snapey, I see. Yours look cleaner :)

12th January, 2018

aripal left a reply on Increment Value When A Button Is Triggered • 5 days ago

Thanks for the feedback, well appreciated! But I find the solution on stackoverflow to solve my problem in a viable way.

Controller file:


public function show(Hour $post)
{
    $months = request('months', 0);
if (request('date') === 'next'){
    $posts = $post->date->addMonth();
    $months++;
} elseif(request('date') === 'prev'){
    $posts = $post->date->subMonth();
    $months--; 
}


return view('user.table', compact('posts', 'months')); 

}

The view:


Previous
Next

Link to stackoverflow solution: https://stackoverflow.com/questions/48203080/next-prev-month-is-not-working-in-laravel/48203322#48203322

11th January, 2018

aripal left a reply on Increment Value When A Button Is Triggered • 6 days ago

Can you give any examples :)

aripal left a reply on Increment Value When A Button Is Triggered • 6 days ago

@Snapey, thank you. But I do not want to use paginate in this scenario. There must be a way I can increment the value each time the user clicks the button.

What I am essentially trying to achieve is to show the user the rows for the next month.

And when that query parameter href=/?date=next, I run this method $post->date->nextMonth().

However, when the function is triggered, it does not update to the next month. Therefore I thought I just might add a value that increments to achieve this, like $post->date->nextMonth($count).

Any other alternatives?

aripal left a reply on Increment Value When A Button Is Triggered • 6 days ago

@Snapey, I added a property protected $count = 0; in the same class. Usually that works in other coding langauges when the function is called..

Where should I save the value so I can use the increment?

10th January, 2018

aripal started a new conversation Increment Value When A Button Is Triggered • 1 week ago

So I have two buttons, one is next and the other is prev. My objective is to increment the value everytime the button is clicked.. I guess after this I should just sell groceries or something, maybe I need some sleep, idk!...

Anyway, I would love to know how to do this..

Blade file


    href="/?date=next"
    href="/?date=prev"

Controller file


    public function show(Hour $post){
        if(request()->has('date')){
            if(request('date') == 'next'){
                $this->count++;
                dd($this->count); // This value is not incrementing  
            }
        }
    }

aripal started a new conversation Redirect And Update The View • 1 week ago

I have a table that shows data inserts for a given month. In addition, I also have a href button that will show the next month when user clicks it with updated data.

The problem is that the return \Redirect::back()->with(compact('posts')); works, but the data is not updated in the table.. I have found different ways of using redirect and route but none of them seem to work for my objective.

I just want the table to be updated with the new data that is triggered by the button. Is there anything I am doing wrong?

How it locks in my template file


Next

How it looks in controller file


public function nextMonth(Hour $post){
 // Update month and return updated data
 ....

// Update view return \Redirect::back()->with(compact('posts')); }

7th January, 2018

aripal started a new conversation Convert Dates In Table Using Carbon • 1 week ago

So I am working on this application where the user selects the date he visited the site, the date is stored like this '05, 10, 2020' in the table.

I do not have any issues using Carbon with created_at since it is a Carbon instance. But whenever I try using the date selected by the user I need to use createFromFormat. I do believe it should be simpler than mine approach..

Anyway, my options are, either to convert the dates that are already in the table and return to the views from the model class, or simply convert the date on-the-fly when the user submits it using Carbon.

Format date on-the-fly in Controller:

 
$hour = Hour::create([
 'date' => Carbon::createFromFormat('d, m, Y', request('dateWorked')),
]);

Format date using method in Model.php class:

public function formatDate(){
 return Carbon::createFromFormat('d, m, Y', $this->date);
}

I would like to know what is a practical and a clean way of doing so using Carbon?

Edit Your Profile
Update

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