public function addComment(Request $request, $articleId)
 {
     $this->validate($request, ['comment' => 'required']);
     $this->comment->add($request, $articleId);
     $data = fractal()->item($this->article->find($articleId))->transformWith(new ArticleTransformer())->includeAuthors()->includeComments()->toArray();
     return response()->json($data, 201);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $category = Category::findOrFail($id);
     $paginator = $category->posts()->paginate(9);
     $posts = $paginator->getCollection();
     $data = fractal()->collection($posts)->transformWith(new PostTransformer())->includeUser()->includeCategories()->paginateWith(new IlluminatePaginatorAdapter($paginator))->toArray();
     return $this->respond($data);
 }
 /**
  * Register the application services.
  */
 public function register()
 {
     $this->mergeConfigFrom(__DIR__ . '/../resources/config/laravel-fractal.php', 'laravel-fractal');
     $this->app->bind('laravel-fractal', function (...$arguments) {
         return fractal(...$arguments);
     });
     $this->app->alias(Fractal::class, 'laravel-fractal');
 }
Exemplo n.º 4
0
 /**
  * Add the upload file to the mediaLibrary.
  *
  * @param \App\Http\Requests\Back\AddMediaRequest $request
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function add(AddMediaRequest $request)
 {
     $model = $this->getModelFromRequest($request);
     $media = $model->addMedia($request->file('file'))->withCustomProperties(['temp' => $request->has('redactor') ? false : true])->toCollection($request->get('collection_name', 'default'));
     if ($request->has('redactor')) {
         return Response::json(['filelink' => $media->getUrl('redactor')]);
     }
     return Response::json(['media' => fractal()->item($media)->transformWith(new MediaTransformer())->toArray()]);
 }
Exemplo n.º 5
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $post = Post::find($id);
     if (!$post) {
         return $this->respondNotFound('Post Not Found');
     }
     $data = fractal()->item($post)->transformWith(new PostTransformer())->includeUser()->includeCategories()->toArray();
     return $this->respond($data);
 }
Exemplo n.º 6
0
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @param $cardNumber
  *
  * @return Response
  */
 public function store(Request $request, $cardNumber)
 {
     $this->validate($request, ['balance' => 'required|numeric|min:0']);
     $balance = $request->input('balance');
     $card = Card::firstOrCreate(['number' => $cardNumber]);
     $currentBalance = $card->addBalance($balance);
     if ($currentBalance->wasRecentlyCreated) {
         return $this->respondCreated(fractal()->item($currentBalance, new BalanceTransformer())->toArray());
     }
     return $this->respond(fractal()->item($currentBalance, new BalanceTransformer())->toArray());
 }
Exemplo n.º 7
0
 public function login(Request $request, User $user)
 {
     $this->validate($request, ['email' => 'required', 'password' => 'required']);
     $users = $this->user->login($request);
     if (!$users) {
         return response()->json(['error' => 'Your credential didn\'t match'], 400);
     }
     $user = $this->user->byEmail($request->email)->first();
     $data = fractal()->item($user)->transformWith(new UserTransformer())->addMeta(['api_token' => $user->api_token])->toArray();
     return response()->json($data, 200);
 }
Exemplo n.º 8
0
 public function media($subject, $collection, $type, $associated = [])
 {
     $initialMedia = htmlspecialchars(fractal()->collection($subject->getMedia($collection))->transformWith(new MediaTransformer())->toJson());
     $model = htmlspecialchars(collect(['name' => get_class($subject), 'id' => $subject->id]));
     if (!array_key_exists('locales', $associated)) {
         $associated['locales'] = config('app.locales');
     }
     $associatedData = collect($associated)->map(function ($data, $key) {
         $json = htmlspecialchars(json_encode($data));
         return "data-{$key}=\"{$json}\"";
     })->implode(' ');
     return "<div data-media-collection=\"{$collection}\"\n                     data-media-type=\"{$type}\"\n                     data-initial=\"{$initialMedia}\"\n                     data-model=\"{$model}\"\n                     {$associatedData}>\n                </div>";
 }
 public function add(AddMediaRequest $request)
 {
     $model = $this->getModelFromRequest($request);
     $files = $request->file('file');
     if (!is_array($files)) {
         $files = [$files];
     }
     $media = collect($files)->map(function (UploadedFile $file) use($model, $request) {
         return $model->addMedia($file)->withCustomProperties(['temp' => $request->has('redactor') ? false : true])->toCollection($request->get('collection_name', 'default'));
     });
     if ($request->has('redactor')) {
         return Response::json(['filelink' => $media->first()->getUrl('redactor')]);
     }
     return fractal()->collection($media)->transformWith(new MediaTransformer());
 }
						<?php 
            do_action('rocket_lift_parent_theme_attribution');
            ?>
					</div><!-- .site-info -->
				<?php 
        });
        /* end 'html-footer' fractal */
        ?>
			</footer><!-- #colophon .site-footer -->
			
		</div><!-- #page .hfeed .site -->
		
		<?php 
        fractal_wp_footer();
        ?>
		
	<?php 
    });
    /* end 'html-body' fractal */
    ?>
	</body>

	</html>
<?php 
});
/* end 'base' fractal */
?>

<?php 
fractal();
				<h2 class="widgettitle"><?php 
    _e('Most Used Categories', 'rocket_lift_parent_theme');
    ?>
</h2>
				<ul>
				<?php 
    wp_list_categories(array('orderby' => 'count', 'order' => 'DESC', 'show_count' => 1, 'title_li' => '', 'number' => 10));
    ?>
				</ul>
			</div><!-- .widget -->
	
			<?php 
    /* translators: %1$s: smilie */
    $archive_content = '<p>' . sprintf(__('Try looking in the monthly archives. %1$s', 'rocket_lift_parent_theme'), convert_smilies(':)')) . '</p>';
    the_widget('WP_Widget_Archives', 'dropdown=1', "after_title=</h2>{$archive_content}");
    ?>
	
			<?php 
    the_widget('WP_Widget_Tag_Cloud');
    ?>
	
		</div><!-- .entry-content -->
	</article><!-- #post-0 .post .error404 .not-found -->
<?php 
});
/* end 'content' fractal block */
?>

<?php 
fractal('base');
Exemplo n.º 12
0
 /**
  * Display the specified resource.
  *
  * @param int     $number
  * @param Request $request
  *
  * @return Response
  */
 public function show($number, Request $request)
 {
     $card = Card::where('number', $number)->firstOrFail();
     return $this->respond(fractal()->item($card, new CardTransformer())->parseIncludes($request->input('include', []))->toArray());
 }
 /**
  * Display a listing of the resource.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $neighborhoods = Neighborhood::orderBy('name')->get();
     return $this->respond(fractal()->collection($neighborhoods, new NeighborhoodTransformer())->parseIncludes($request->input('include', []))->toArray());
 }
<?php

/**
 * The template for displaying 404 pages (Not Found).
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('404');
Exemplo n.º 15
0
 /**
  * Display a listing of the resource.
  *
  * @param Request $request
  *
  * @return Response
  */
 public function index(Request $request)
 {
     $districts = District::all();
     return $this->respond(fractal()->collection($districts, new DistrictTransformer())->parseIncludes($request->input('include', []))->toArray());
 }
Exemplo n.º 16
0
 public function index()
 {
     $agencies = Agency::all();
     return $this->respond(fractal()->collection($agencies, new AgencyTransformer())->toArray());
 }
 public function show(Request $request, $uuid)
 {
     return fractal()->item(Faction::byUuid($uuid), new FactionTransformer(), 'faction')->parseIncludes($this->getIncludesFromRequest($request))->toArray();
 }
Exemplo n.º 18
0
 public function media($subject, string $collection, string $type, $associated = []) : string
 {
     $initialMedia = fractal()->collection($subject->getMedia($collection))->transformWith(new MediaTransformer())->toJson();
     $model = collect(['name' => get_class($subject), 'id' => $subject->id])->toJson();
     return el('blender-media', ['collection' => $collection, 'type' => $type, 'upload-url' => action('Back\\Api\\MediaLibraryController@add'), ':model' => htmlspecialchars($model), ':initial' => htmlspecialchars($initialMedia), ':data' => htmlspecialchars($this->getAssociatedMediaData($associated))], '');
 }
<?php

/**
 * The Template for displaying all single posts.
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('single');
<?php

/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('page');
<?php

/**
 * The template for displaying image attachments.
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
?>

<?php 
fractal_template();
?>

<?php 
fractal('image');
<?php

/**
 * The template for displaying the home page.
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('front-page');
<?php

/**
 * The template for displaying Archive pages.
 *
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('archive');
<?php 
});
?>

<?php 
fractal_block('section-1', function () {
    ?>
	<h2>sub-title section 1 (from index-2)</h2>
	<?php 
    fractal_parent();
});
?>

<?php 
fractal_block('section-2', function () {
    ?>
	<h2>sub-title section 2 (from index-2) </h2>
	<?php 
    fractal_parent();
});
?>

<?php 
fractal_block('section-3', function () {
    ?>
	<h2>sub-title section 3 (from index-2)</h2>
	<?php 
    fractal_parent();
});
fractal('index-3');
<?php

/**
 * The main template file.
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 * Learn more: http://codex.wordpress.org/Template_Hierarchy
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('index');
<?php

/**
 * The template for displaying Search Results pages.
 *
 * @package Rocket Lift Parent Theme
 * @since Rocket Lift Parent Theme 1.0
 */
fractal_template();
?>

<?php 
fractal('search');
<?php

fractal_template();
fractal_block('section-1', function () {
    ?>
	<h1>Section 1</h1>
	<?php 
    fractal_parent();
});
?>

<?php 
fractal_block('section-2', function () {
    ?>
	<h1>Section 2</h1>
	<?php 
    fractal_parent();
});
?>

<?php 
fractal_block('section-3', function () {
    ?>
	<h1>Section 3</h1>
	<?php 
    fractal_parent();
});
fractal('index-2');
				</div><!-- .entry-caption -->
				<?php endif; ?>
			</div><!-- .entry-attachment -->
	
			<?php the_content(); ?>
			<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'rocket_lift_parent_theme' ), 'after' => '</div>' ) ); ?>
	
		</div><!-- .entry-content -->
	
		<footer class="entry-meta">
			<?php if ( comments_open() && pings_open() ) : // Comments and trackbacks open ?>
				<?php printf( __( '<a class="comment-link" href="#respond" title="Post a comment">Post a comment</a> or leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', 'rocket_lift_parent_theme' ), get_trackback_url() ); ?>
			<?php elseif ( ! comments_open() && pings_open() ) : // Only trackbacks open ?>
				<?php printf( __( 'Comments are closed, but you can leave a trackback: <a class="trackback-link" href="%s" title="Trackback URL for your post" rel="trackback">Trackback URL</a>.', 'rocket_lift_parent_theme' ), get_trackback_url() ); ?>
			<?php elseif ( comments_open() && ! pings_open() ) : // Only comments open ?>
				<?php _e( 'Trackbacks are closed, but you can <a class="comment-link" href="#respond" title="Post a comment">post a comment</a>.', 'rocket_lift_parent_theme' ); ?>
			<?php elseif ( ! comments_open() && ! pings_open() ) : // Comments and trackbacks closed ?>
				<?php _e( 'Both comments and trackbacks are currently closed.', 'rocket_lift_parent_theme' ); ?>
			<?php endif; ?>
			<?php edit_post_link( __( 'Edit', 'rocket_lift_parent_theme' ), ' <span class="edit-link">', '</span>' ); ?>
		</footer><!-- .entry-meta -->
	</article><!-- #post-<?php the_ID(); ?> -->
	
	<?php fractal_block( 'comments', function(){
		fractal_parent();
	}); ?>

<? }); ?>

<?php fractal( 'base' );