darkcyber

darkcyber

Member Since 4 Years Ago

Experience Points
1,100
Total
Experience

3,900 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

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

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
1,100 XP
Oct
31
1 year ago
Activity icon

Started a new conversation How To Create Feature That Can Create Many Email Template

Hi,

There is custom email template in mailchimp we can make as many template as we like, as custom as we want. I want to adapt these feature in simply version. so I want to make some function in my website which can create many email template with custom design (no drag drop).

What I though is maybe I can type full source code (html and css) which contain {{ $var }} in text area then submit it, and the system will create new blade template. then in controller or somewhere I should prepare $var and then call the email template I want.

Is this way safe and good? or is there any other recomendation?

thanks in advance.

Sep
29
4 years ago
Activity icon

Replied to URL With Trailing Slashes Gets Redirected To Localhost

@Snapey Which one is multiple directory? then how to fix it?

I am currently in development mode @ localhost, so i need acces to other folder for testing purpose.

Sep
28
4 years ago
Activity icon

Started a new conversation URL With Trailing Slashes Gets Redirected To Localhost

I can access my url with http://localhost/rnd/public/coeg-admin but if I visit http://localhost/rnd/public/coeg-admin/ it gets redirected to http://localhost/coeg-admin.

I just follow http://stackoverflow.com/questions/21735527/laravel-trailing-slashes-redirect-to-localhost and http://stackoverflow.com/questions/30775997/url-with-trailing-slashes-gets-redirected-to-localhost-in-laravel-5

But it's doesn't work as expected, Here is my .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Set base URL
    # RewriteBase /rnd/public/
    # RewriteRule ^(.*)/$ /$1 [L,R=301]
    # RewriteCond %{REQUEST_URI} !^

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

Here is my apache2.conf

<Directory "/var/www/html/rnd/public">
        Options Indexes FollowSymLinks
        #AllowOverride None
        AllowOverride All
        Require all granted
</Directory>

<Directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

How, I can redirect url with slashes at the end to url without slashes at the end ?

Thanks, any help appreciated.

Sep
05
4 years ago
Activity icon

Replied to [ASK] Help Me Understanding Relation Table And How To Use It ?

@kriky1 @francoboy7

i found this simple and easy to understand tutorial about relationships

https://scotch.io/tutorials/a-guide-to-using-eloquent-orm-in-laravel

but i missunderstanding few things, please help me to understand it, in fish migration

$table->integer('bear_id');

its different with the docs to create relation (foreign key),which says :

$table->integer('bear_id')->unsigned();
$table->foreign('bear_id')->references('id')->on('bear');

is that way is alternative to create relation in simple way instead of using below code ?

->foreign()->references()->on()

If so, can you please refer to me the docs about it ? AFAIK the docs says to create relation we need to use

$table->foreign()->references()->on()

Oh one more again, is it possible to use onDelete() and onUpdate() like below code in original fish migration in that tutorial ?

$table->integer('bear_id')->onDelete('cascade')->onUpdate('cascade');

Thanks.

Aug
27
4 years ago
Activity icon

Replied to [ASK] Help Me Understanding Relation Table And How To Use It ?

@kriky1

Thanks for reply Can you please give me example for many to many in this case posts has many categories, and categories has many posts ? Thanks.

Activity icon

Started a new conversation [ASK] Help Me Understanding Relation Table And How To Use It ?

Hi, Sorry I Just miss understanding about relationships. In this case i want to create one to one relation, a post has many category let's assume i have POSTS table and CATEGORIES table

POSTS -> id, title, content, category
CATEGORIES -> id, name

POSTS -> 1, Network for Dummy, this is content, 1
POSTS -> 2, PHP, this is content , 2
POSTS -> 3, Computer for kids, this is content, 3

CATEGORIES -> 1,networking
CATEGORIES -> 2,programming
CATEGORIES -> 3, basic

how i can create relation in PhpMyadmin, but why we have to make relation ? what excactly laravel eloquent relationship do with this function ?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * Get the phone record associated with the user.
     */
    public function phone()
    {
        return $this->hasOne('App\Phone');
    }
}

and

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Phone extends Model
{
    /**
     * Get the user that owns the phone.
     */
    public function user()
    {
        return $this->belongsTo('App\User');
    }
}

What i think in this case is i just to input post title, content, and category id, i think i don't need to create relation. so please tell me the important thing using relation ship ?

Sorry i am new here and sory for my bad english.

Apr
20
4 years ago
Activity icon

Replied to How To Find Real App Folder ?

@toniperic i think virtual host already pointed to /var/www/www.target.com/public because in httpd/conf.d I see

<VirtualHost *:443>
    SSLEngine on
    SSLCertificateFile "/etc/ssl/certs/PA/ca.crt"
    SSLCertificateKeyFile "/etc/ssl/certs/PA/ca.key"
    SSLCACertificateFile "/etc/ssl/certs/PA/bundle.crt"

    <Directory /var/www/domains/www.target.com/public>
    AllowOverride All
    </Directory>
    DocumentRoot /var/www/domains/www.target.com/public
    ServerName target.com
    ServerAlias www.target.com
</VirtualHost>

and website open normally, i try this with web shell, i just need to find where is the controllers, views, routes and do something with them, then i report it to client. because i dont see something usefull in /var/www/domains/www.target.com/app/controllers, /views & /routes.php, but i can create file in /var/www/domains/www.target.com/public/file.txt and access my new file with www.target.com/file.txt, what i think is real app folder is in other directory or in other server, am I right ? so i call it weird because normal Laravel should put controllers, views in /app but in this case i can't find controllers, views in /app.

Thanks for your attention :D

Activity icon

Started a new conversation How To Find Real App Folder ?

Hello, i do some security audit to website built with Laravel.

I try to put some file in /var/www/domains/www.target.com/public/x.txt , now i can access file with https://www.target.com/x.txt, yes it shows the content.

and i see some weird structure inside /var/www/domains/www.target.com/app/views and /controllers, there is just useless file and folder which not related to real site, and routes.php contain no route.

Then i create some simple route in /var/www/domains/www.target.com/app/routes.php

Route::get('someone', function(){
    return 'Hello someone';
});

But its show Page not found when I visit https://www.target.com/someone the servers looks like use multi domain in single server because i can see folders might be related to https://target.com/ in /var/www/domains/ , but i can't find where is the real app folder of https://target.com, hope anyone can help my weird problem maybe with some debuggin or something ? :D

Feb
04
4 years ago
Activity icon

Started a new conversation Chumper Datatable : How To Get Column From Array ?

Hello,

my controller

    public function getCategoriesTable()
    {
        $categories = Term::with(['TermTaxonomy' => function($q){
            $q->select('term_id', 'description');
        }])->orderBy('term_id', 'desc')->get(['term_id', 'slug', 'name']);

        return Datatable::collection($categories)
        ->showColumns('name', 'slug', 'term_taxonomy', 'term_id')
        ->make();

    }

then the result is like below

{

    "aaData": 

[

[

    "2na",
    "2slu",

    {
        "term_taxonomy_id": 63,
        "term_id": 77,
        "taxonomy": "category",
        "description": "2desc",
        "parent": 0,
        "count": 0,
        "created_at": "2015-02-04 08:29:06",
        "updated_at": "2015-02-04 08:29:06"
    },
    77

],
and so on

how i can get only description instead of term_taxonomy table ? it should look like this

->showColumns('name', 'slug', 'term_taxonomy.description', 'term_id')

but the above code generate null value.

Thanks, for all.

Jan
29
4 years ago
Activity icon

Replied to WithInput() Cause Other Form DELETE Method Change To PATCH Method

@jekinney just trying change my delete form with original foundation

{{ link_to('#', 'Delete', ['data-reveal-id' => 'myModal'.$category->term_id, 'class' => 'button small expand']) }}
                            <div id="myModal{{ $category->term_id }}" class="reveal-modal" data-reveal>
                                <h2>Are you sure ?</h2>
                                <p>Wanna to delete <i><b>{{ $category->name }}</b></i> category. This action can't be undone.</p>
                                <p><b>Please be careful to make your decision.</b></p>
                                <a class="close-reveal-modal">&#215;</a>
                                {{ Form::open(['route' => ['admin_posts_categories_destroy', $category->term_id], 'method' => 'DELETE' ]) }}
                                {{ Form::submit('Delete', ['class' => 'button small expand']) }}
                                {{ Form::close() }}
                            </div>

and still not working

@AlnourAltegani change my method PATCH to PUT in form model section and cause DELETE method change to PUT , in my previous post DELETE method change to PATCH because my form model section use PATCH.

so i am not sure this problem happen because withInput() or because wrong using form model binding.

fyi my form section which have update and create function

        <div class="medium-4 columns">

        @if (isset($categoryEdit))
            {{ Form::model($categoryEdit, ['route' => ['admin_posts_categories_update', $categoryEdit->term_id], 'method' => 'PUT']) }}
        @else
            {{ Form::open(['route' => 'admin_posts_categories_store'])}}
        @endif 

            {{ Form::label('name', 'Name') }}
            <span data-tooltip aria-haspopup="true" class="has-tip radius" title="Category name for your posts.">
            {{ Form::text('name', null, ['placeholder' => 'Category name here']) }}
            @if ($errors->has('name')) <small class="error"> {{ $errors->first('name') }} </small> @endif
            </span>

            {{ Form::label('slug', 'Slug') }}
             <span data-tooltip aria-haspopup="true" class="has-tip radius" title="Slug or URL for your category.">
            {{ Form::text('slug', null, ['placeholder' => 'Slug here']) }}
            @if ($errors->has('slug')) <small class="error"> {{ $errors->first('slug') }} </small> @endif
            </span>

            {{ Form::label('description', 'Description') }}
            {{ Form::textarea('TermTaxonomy[description]', null, ['placeholder' => 'Category description here', 'size' => '50x5']) }}

        @if (isset($categoryEdit))        
            {{ Form::submit('Update', ['class' => 'radius button']) }}
        @else
            {{ Form::submit('Add New Category', ['class' => 'radius button']) }}
        @endif

        {{ Form::close() }}
        </div>

let me know if my above code is correct to detect user want to update or create new

and here is full html output if current page show failed to update, all form open and closed correctly http://laravel.io/bin/GyqlP

actually not all html output because firefox inspect element can't copy all output , and if i copy from view source , the html code is different with real html output.

Thanks all.

Activity icon

Replied to Redirect::intended() Not Working Correctly

@usman @bestmomo now its working , sorry forget editing old redirect if login succes. Thanks you all , very much.

Activity icon

Replied to Redirect::intended() Not Working Correctly

@usman just trying your code and still not working.

Jan
28
4 years ago
Activity icon

Replied to WithInput() Cause Other Form DELETE Method Change To PATCH Method

@jekinney i use http://blog.agoragames.com/confirm-with-reveal/ which do you mean data-confirm set up wrong ?

let me know more detail about what you meant by use modal , and put form in modal ?

thanks.

Activity icon

Started a new conversation Redirect::intended() Not Working Correctly

if use Intended() after login success it should redirect to last url which user trying to access, but with below code it redirect to root path of my app like http://localhost/coeg_cms/

anyway i try to direct access http://localhost/coeg_cms/sempak/posts/categories , when i not logged in , thus url is available.

my filter

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::route('admin_login')->withError('You must be logged in !');
        }
    }
});

my login controller

public function store()
    {
        $data = Input::all();
        $user = new User;

        if ($user->isValid($data) == true){
            $cok = ['user_email' => $data['email'], 'password' => $data['password']];

            if(Auth::attempt($cok)){
                return Redirect::intended();
            }else{
                return Redirect::route('admin_login')->withError("Sorry, login failed.");
            }
        }else{
            $gagal = $user->gagal();
            return Redirect::route('admin_login')->withErrors($gagal);
        }
    }

so how to fix this weird intended issue() , is something wrong with my code ?

Activity icon

Replied to WithInput() Cause Other Form DELETE Method Change To PATCH Method

@AlnourAltegani if current page show failed to update (which cause DELETE method change to PATCH) , here is html output.

                                        <tr>
                        <td>abcd3222</td>
                        <td>abcddfd</td>
                        <td>abcd23</td>
                        <td>
<!--                            -->
<!--                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/58" accept-charset="UTF-8" class="delete-form"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K"><input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>abcd3222</b> category. This action cannot be undone."}" type="submit" value="Delete"></form>-->
<!--                            -->

                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/58" accept-charset="UTF-8"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K">
                            <input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>abcd3222</b> category. This action cannot be undone."}" type="submit" value="Delete">
                            </form>

                            <a href="http://mata.mu/coeg_cms/sempak/posts/categories/58/edit" class="button small expand">Edit</a>
                        </td>
                    </tr>
                                        <tr>
                        <td>a</td>
                        <td>a</td>
                        <td>a</td>
                        <td>
<!--                            -->
<!--                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/57" accept-charset="UTF-8" class="delete-form"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K"><input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>a</b> category. This action cannot be undone."}" type="submit" value="Delete"></form>-->
<!--                            -->

                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/57" accept-charset="UTF-8"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K">
                            <input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>a</b> category. This action cannot be undone."}" type="submit" value="Delete">
                            </form>

                            <a href="http://mata.mu/coeg_cms/sempak/posts/categories/57/edit" class="button small expand">Edit</a>
                        </td>
                    </tr>
                                        <tr>
                        <td>cogname</td>
                        <td>cogslug</td>
                        <td>cogdesc</td>
                        <td>
<!--                            -->
<!--                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/43" accept-charset="UTF-8" class="delete-form"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K"><input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>cogname</b> category. This action cannot be undone."}" type="submit" value="Delete"></form>-->
<!--                            -->

                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/43" accept-charset="UTF-8"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K">
                            <input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>cogname</b> category. This action cannot be undone."}" type="submit" value="Delete">
                            </form>

                            <a href="http://mata.mu/coeg_cms/sempak/posts/categories/43/edit" class="button small expand">Edit</a>
                        </td>
                    </tr>
                                        <tr>
                        <td>111zzz</td>
                        <td>111xxx</td>
                        <td>111yyyz</td>
                        <td>
<!--                            -->
<!--                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/38" accept-charset="UTF-8" class="delete-form"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K"><input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>111zzz</b> category. This action cannot be undone."}" type="submit" value="Delete"></form>-->
<!--                            -->

                            <form method="POST" action="http://mata.mu/coeg_cms/sempak/posts/categories/38" accept-charset="UTF-8"><input name="_method" type="hidden" value="PATCH"><input name="_token" type="hidden" value="ATQr2OqRfIIbFajAkEc0qFG4G8pv96wmG1nOxZ8K">
                            <input class="button small expand" data-confirm="{"title" : "Are you sure ?", "body" : "To delete <b>111zzz</b> category. This action cannot be undone."}" type="submit" value="Delete">
                            </form>

                            <a href="http://mata.mu/coeg_cms/sempak/posts/categories/38/edit" class="button small expand">Edit</a>
                        </td>
                    </tr>
Activity icon

Started a new conversation WithInput() Cause Other Form DELETE Method Change To PATCH Method

i have page which show all categories, form to create and update category using form model binding, then form to delete category since i use RESTful

here is my page looks like

my View

    <div class="row panel">
        <div class="medium-4 columns">
        @if (isset($categoryEdit))
            {{ Form::model($categoryEdit, ['route' => ['admin_posts_categories_update', $categoryEdit->term_id], 'method' => 'PATCH']) }}
        @else
            {{ Form::open(['route' => 'admin_posts_categories_store'])}}
        @endif 

            {{ Form::label('name', 'Name') }}
            <span data-tooltip aria-haspopup="true" class="has-tip radius" title="Category name for your posts.">
            {{ Form::text('name', null, ['placeholder' => 'Category name here']) }}
            @if ($errors->has('name')) <small class="error"> {{ $errors->first('name') }} </small> @endif
            </span>

            {{ Form::label('slug', 'Slug') }}
             <span data-tooltip aria-haspopup="true" class="has-tip radius" title="Slug or URL for your category.">
            {{ Form::text('slug', null, ['placeholder' => 'Slug here']) }}
            @if ($errors->has('slug')) <small class="error"> {{ $errors->first('slug') }} </small> @endif
            </span>

            {{ Form::label('description', 'Description') }}
            {{ Form::textarea('TermTaxonomy[description]', null, ['placeholder' => 'Category description here', 'size' => '50x5']) }}

        @if (isset($categoryEdit))        
            {{ Form::submit('Update', ['class' => 'radius button']) }}
        @else
            {{ Form::submit('Add New Category', ['class' => 'radius button']) }}
        @endif

        {{ Form::close() }}
        </div>
        <div class="medium-8 columns">
            <table role="grid" class="display responsive hover" id="categoriesTable" width="100%">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Slug</th>
                        <th>Description</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($categories as $category)
                    <tr>
                        <td>{{ $category->name }}</td>
                        <td>{{ $category->slug }}</td>
                        <td>{{ ($category->TermTaxonomy ? $category->TermTaxonomy->description : '') }}</td>
                        <td>
                            {{ Form::open(['route' => ['admin_posts_categories_destroy', $category->term_id], 'method' => 'DELETE']) }}
                            {{ Form::submit('Delete', ['class' => 'button small expand', 'data-confirm' => "{\"title\" : \"Are you sure ?\", \"body\" : \"To delete <b>$category->name</b> category. This action cannot be undone.\"}" ])}}
                            {{ Form::close() }}

                            {{ link_to_route('admin_posts_categories_edit', 'Edit' , [$category->term_id],['class' => 'button small expand']) }}
                        </td>
                    </tr>
                    @endforeach
                </tbody>
                <tfoot>
                    <tr>
                        <th>Name</th>
                        <th>Slug</th>
                        <th>Description</th>
                        <th>Action</th>
                    </tr>
                </tfoot>
            </table>
        </div>
    </div>

my CategoriesController

    public function edit($id)
    {
        $categories = Term::with(['TermTaxonomy' => function($q){
            $q->select('term_id', 'description');
        }])->orderBy('term_id', 'desc')->get(['term_id', 'name', 'slug']);

        $categoryEdit = Term::with(['TermTaxonomy' => function($q){
            $q->select('term_id', 'description');
        }])->find($id, ['term_id', 'name', 'slug']);

        return View::make('qhymchildz.backend.posts.categories', compact('categoryEdit', 'categories'));
    }

    public function update($id)
    {
        $data = Input::all();
        $category = Term::with('TermTaxonomy')->find($id);
        if($category->updateCategory($data)){
            return Redirect::route('admin_posts_categories')->withSuccess('Category successfully updated.');
        }
        else{
            return Redirect::route('admin_posts_categories_edit', $id)->withError('Failed to update category.')->withErrors($category->validation_messages());
        }
}

my Term model

    public function updateCategory($data){
        $validator = Validator::make($data,$this->rules);
        if($validator->passes()){
        $this->name = $data['name'];
        $this->slug = $data['slug'];
        $this->TermTaxonomy->taxonomy = 'category';
        $this->TermTaxonomy->description = $data['TermTaxonomy']['description'];
            if($this->push()){
                    return true;
            }else{
                    return false;
            }
        }else{
            $this->errors = $validator;
            return false;
        } 
    }

with my above code yes i can CRUD my page. then when user failed to update because not passing Validation, it redirect to my view and populate my input text with current $id because i pass data to my view with this code, in edit method of my controller

        $categoryEdit = Term::with(['TermTaxonomy' => function($q){
            $q->select('term_id', 'description');
        }])->find($id, ['term_id', 'name', 'slug']);

        return View::make('qhymchildz.backend.posts.categories', compact('categoryEdit', 'categories'));

so, what i want is when user failed to update because not passing validation it redirect to view with previous input not current data of $id, i think your answer is change your redirect error section like this.

return Redirect::route('admin_posts_categories_edit', $id)->withError('Failed to update category.')->withErrors($category->validation_messages())->withInput();

if i use withInput() like the code above my DELETE method form will change to PATCH method, and my input text populated with previous input , if i correct my input text after failed , then click update, yes it work like i want.

like this picture

so if i click delete when current page show failed to update , it will show confirm dialog, then it will redirect to show edit url like /categories/57/edit or /categories/56/edit depends on what id.

in this case i click delete in category "a" so the result like this picture

so the problem is i cant delete category if current page show update failed, because DELETE method, change to PATCH method silently, let me know why and how to fix this problem ? dont know if error is from my code, or because i use withInput()

Activity icon

Replied to How To Insert Related Data Using Push() Instead Of Save() In Laravel ?

@JarekTkaczyk Thanks, working like a charm, marked as solved.

Jan
27
4 years ago
Activity icon

Replied to How To Insert Related Data Using Push() Instead Of Save() In Laravel ?

@JarekTkaczyk

almost complete description now inserted, but how i can input

$category->TermTaxonomy->taxonomy = 'category';

Thanks.

Activity icon

Replied to How To Insert Related Data Using Push() Instead Of Save() In Laravel ?

@JarekTkaczyk

your code seems not working completely, description not inserted. since i use this in my view

{{ Form::textarea('TermTaxonomy[description]', null, ['placeholder' => 'Category description here', 'size' => '50x5']) }}

so the name of my description input is "TermTaxonomy[description]" not "description" , because i use Form model binding which has eager load.

then what about to input

$category->TermTaxonomy->taxonomy = 'category';

Thanks in advance.

Activity icon

Replied to How To Insert Related Data Using Push() Instead Of Save() In Laravel ?

@bestmomo without () , i get Indirect modification of overloaded property Term::$TermTaxonomy has no effect

@JarekTkaczyk then what is your easy and nice recomendation in my case ?

Activity icon

Started a new conversation How To Insert Related Data Using Push() Instead Of Save() In Laravel ?

as offical documentation says :

Sometimes you may wish to save not only a model, but also all of its relationships. To do so, you may use the push method:
Saving A Model And Relationships
$user->push();

Terms table:

  • term_id
  • name
  • slug

Term_taxonomy table:

  • term_taxonomy_id
  • term_id
  • description

My Term model:

    public function TermTaxonomy(){
        return $this->hasOne('TermTaxonomy');
    }

My TermTaxonomy model:

    public function Term(){
        return $this->belongsTo('Term');
    }

my CategoriesController

public  function store(){
    $data = Input::all();
    $category = new Term;
    $category->name = $data['name'];
    $category->slug = $data['slug'];
    $category->TermTaxonomy()->taxonomy = 'category';
    $category->TermTaxonomy()->description  = $data['TermTaxonomy']['description'];
    $category->push();  
}

with my code above, I can save name and slug, but taxonomy and description not inserted. how i can do it with push() instead of save() ? is it possible ?

Thanks, i am new in Laravel.