duanmao9918 2014-09-15 17:52
浏览 28

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

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.

  • 写回答

1条回答 默认 最新

  • doutan1875 2014-09-15 18:55
    关注

    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();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂