如何在这里使用急切加载,我的意思是只使用一个变量而不是两个。 所以我不需要运行两个单独的查询

1) How can use eager loading here, i mean just by using $SponceringUser instead of $ProfileUser. so i don't need to run two separate queries.

if i exchange my $profileUser variable with $SponceringUser where in the code i should save it to get the right output

here is the Post_edit method for more details please refer gist here : https://gist.github.com/gupta2205/b33dcf762876e5df34d9

public function post_edit($id = null)
{
if ($id)
{
    $Petition = Petition::find($id);

    if (!$Petition)
    {
        //oh noes! invalid petition specified!
        Alert::error("That petition no longer exists");
        return Redirect::action('AdminPetitionsController@index');
    }
}
else
{
    $Petition = new Petition;
}

$PetitionCreationForm = new AdminPetitionCreationForm;
$errors = array();

if ($PetitionCreationForm->passes())
{
    $Petition->call_to_action = Input::get('call_to_action');

    if (empty($Petition->id))
    {
        $Petition->slug = Str::slug($Petition->call_to_action);
    }

    $Petition->recipient = Input::get('recipient');


    if (Input::get('feature_type') == '1')
    {
        $Petition->featured_sort_order = Input::get('featured_sort_order') + 1;
        $Petition->flag_featured = 1;
    }
    else if(Input::get('feature_type') == '0')
    {
        $Petition->featured_sort_order=null;
        $Petition->flag_featured = 0;
    }
    //$selected_position = Input::get('dropdown_menu_list');
    $Petition->description_md = Input::get('description_md');
    $Petition->description = Petition::parseMD($Petition->description_md);

    $Petition->letter_md = Input::get('letter_md');
    $Petition->letter = Petition::parseMD($Petition->letter_md);

    $Petition->target_signatures = Input::get('target_signatures', 50000);
    $Petition->flag_published = Input::get('flag_published');

    $Petition->media_type = Input::get('media_type', null);

    if (Input::get('media_type') == 'img' && Input::hasFile('petition_image'))
    {
        $Petition->media_url = Petition::uploadFile(Input::file('petition_image'));
    }
    else if (Input::get('media_type') == 'youtube' && Input::get('media_url_youtube'))
    {
        $Petition->media_url = Input::get('media_url_youtube');
    }


    //  how to fix this part .... gurrrrrrrrrrrr=======================
    $ProfileUser= $Petition->User;

    if (Input::get('profile_type') == 'image' && Input::hasFile('profile_image'))
    {
        $ProfileUser->profile_img_url =  Petition::uploadFile(Input::file('profile_image'));
    }
    else if (Input::get('profile_type') == 'url' && Input::get('profile_url'))
    {
        $ProfileUser->profile_img_url = Input::get('profile_url');
    }
    //$Petition->sponsor_user_id = $SponsoringUser->id;
    $ProfileUser->save();
    //====================================================

    try {
        try {
            $SponsoringUser = User::where('email', Input::get('user.email'))->firstOrFail();
        }
        catch (Exception $e)
        {
            $PetitionSponsorForm = new AdminPetitionSponsorForm(Input::get('user'));

            if ($PetitionSponsorForm->passes())
            {
                $SponsoringUser = new User;
                $SponsoringUser->email = Input::get('user.email');
                $SponsoringUser->first_name = Input::get('user.first_name');
                $SponsoringUser->last_name = Input::get('user.last_name');
                $SponsoringUser->populateLocation(Input::get('user.zip'));

                $SponsoringUser->save();
            }
            else
            {
                throw new Exception();
            }
        }
        $Petition->save();

1) How can use eager loading here, i mean just by using $SponceringUser instead of $ProfileUser. so i don't need to run two separate queries.

i got it :)

 if (Input::get('profile_type') == 'image' && Input::hasFile('profile_image'))
            {
                $SponsoringUser->profile_img_url =           Petition::uploadFile(Input::file('profile_image'));
            }
            else if (Input::get('profile_type') == 'url' && Input::get('profile_url'))
            {
                $$SponsoringUser->profile_img_url = Input::get('profile_url');
            }

            $SponsoringUser->save();